Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 4: >> class string
give you class a different name because string is the name of std::string that's in the <string> header file.

What compiler are you using? If TurboC++ then trash it and get a new compiler if you can because some of the code you are writing is non-standard.

line 31: semicolon required at the end of class declarations

lines 20 and 28: variabe s is undeclared.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use friend functions

#include <iostream>
using namespace std; 

class c2;
class c1
{
public:
    friend c2;
    c1() {}
private:
    void SayHello() {cout << "Hello\n";}
};

class c2
{
public:
    c2() { p1 = new c1;}
    ~c2() {delete p1;}
    void Hello() {p1->SayHello();}
private:
    c1* p1;
};

class c3
{
public:
    c3()
    {
        c2 o2;
        o2.Hello();
    }
};

int main()
{
    c3 o3;

    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

OpenClipboard() scroll down a bit and you will see a link to an example

File Mapping

popen() google links

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is there a way to pass a pointer from the parent to the child and have the child populate it?
No because the two probrams are in different address spaces. You could copy the strings to the clipboard or put them into a mem file. Or you could open a pipe to the two programs and parent could read the strings directly through the pipe.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I hope you realize that std::string in c++ programs is not the same as a String in VB. The function exported in the dll needs to be written in such a way that it can be called from languages other than c++, such as this: int _stdcall ss(const char* de) or this int _stdcall ss(VARIANT* de)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>DOS is not an RTOS
What I mean by RTOS is (1) program able to access computer ports directly, (2) program gets real-time hardware interrupts when an event occurs that can be detected by the computer hardware such as serial ports, network cards etc. That can not be done with any version of MS-Windows beyond Win95 and can not be done with WinCE.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first argument to strncmp() is a const char* pointer, but you are just passing a single character.

Suggest you change line 8 like this: if (strncmp (&str2[i], str1, strlen(str1)) == 0) Actually there is an easier way to do this using strstr().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) Stop spamming this board with all those new threads about the same program. Just continue adding to the thread you already have.

2) Learn to use code tags

3) Learn to format your code better so that you and other people can read it easier. I also made a couple changes in randomno() to remove all the extraneous code that isn't needed.

#include<iostream> 
#include<stdlib.h>
#include <ctime>
using std::cout;
using std::endl;

int randomno();

int main()
{    
    int i;   
    srand( (unsigned int)time(0) ); // seed the random number generator
    cout<<"ten random numbers for the range 0 to 50"<<endl;    
    for(i=0;i<10;i++)    
   {      
       cout << randomno() << "\n";    
   }   
}

int randomno()
{    
      return rand() % 50;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 18: >>!cin
To my knowlege that can never happen so you might as well delete it.

Otherwise you program seems to work ok for me.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First figure out how to split the string then worry about how to write the overload operator.

What kind of string -- character array or std::string? How are you supposed to know where to split the string? Is there something in the string that is supposed to tell you where to split it? For example: where would you split this string: "How now brown cow" or "Once upon a time there were three little pigs".

Maybe you need to post the exact requirements of your assignment.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why did you put a return in the middle of main() ? Lines 12-19 will never get executed because of that unconditional return on line 11. Just delete line 11 and the reset will be executed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

file.read((char*)&newServ, sizeof(newServ)); That line won't work for two reasons

  • &newServ -- newServ is already a pointer as declared in the function parameter. So what you are creating with &newServ is a pointer to a pointer, which is not what you want. Remove the & pointer operator.
  • sizeof(newServ)); -- this is taking the size of a pointer, and on 32-bit compilers the size of any pointer is 4. What you want is the size of the Service class. There are two ways you can fix this and both are correct so its up to you which you want. 1) sizeof( *newServ ) or sizeof( Service )

>>while(!file.eof())
What is not the correct way to write that loop because eof() doesn't work that way. Here is how to do it

newServ = new Service; // allocate memory for the read function  
i = 0;
while( file.read((char*)newServ, sizeof(*newServ)) )
{
    newVecService[i] = newServ;
   newServ = new Service; // allocate memory for the read function  
   i++;
}
delete newServ;
newServ = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>(D/4) + (C/4)
This is doing integer arithmetic, meaning all decimals are discarded leaving only the integer portion. try casing to double to see if it fixed your problem -- I don't know whether it will or not ( (double)D / 4.0) + ( (double)C / 4.0)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> file.write((char*)&(*newVecService), sizeof(*newVecService));

try this: file.write((char*)newVecService[i], sizeof(*newVecService[i])); newVecService is alread a pointer -- no need for all that typecasting.

>>void saveFile(vector<Service*> newVecService)
pass the vector by reference to avoid duplicating the vector void saveFile(vector<Service*>& newVecService) >>Service *newServ;
>>vector<Service*> vecService(300,newServ);

You are initializing each of the 300 vector elements with an uninitialized pointer. Initialize the pointer to 0 first Service *newServ = 0;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on whether the child process is a console application or an MS-Windows program. Console: just return the int value from main(). MS-Windows: PostQuitMessage()

On the parent process side: After calling CreateProcess(), call WaitForSingleObject() then when that returns call GetExitCodeProcess() to get the exit status of the spawned program. Note: this does not work well with Mobile 5 wireless MFC programs because the MFC code will return 0 regardless of the parameter in PostQuitMessage().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

moved

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well i'm sorry i do not open links
or read private messages
or even listen to speaches wrote
by fool politicians
you can delete my membership
coz i will not login any more .

Sorry to hear that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> strncpy_s(thevalue,sizeof(thevalue)-1,temp,templength);
theValue is a pointer, so sizeof(theValue) is the size of a pointer which is 4 on all 32-bit compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

two problems:
1) line 29: initialize the pointer to NULL because if the loop beginning on line 31 never finds the first character of the string then the function needs to return a valid pointer -- NULL.

2) Add a break just after the end of the loop on line 43 because at that point it has found the string so no point in looking any further.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Hi I am New I want Vb.net help is anyone there
In the beginning God created the heavens and the earth. Then he created Adam & Eve, who started having babies, granchildren, great grandchildren, etc. etc. Eventually Bill Gates was born and he became the savior of the computer geeks. And Bill Gates said "Let there be an easier way for geeks to write computer programs." And Bill Gates created VB.NET.

Any other questions ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't like their music (trashy as it is) but I do respect their right to get paid for playing it. Afterall, no one wants to work for free unless its for charity or something like that.

With the release of Load in 1996, Metallica distanced itself from earlier releases in what has been described as "an almost alternative [rock] approach", and the band faced accusations of "selling out". Metallica filed a lawsuit in 2000 against Napster for sharing the band's copyrighted material for free without the members' consent. A settlement was reached, and Napster became a pay-to-use service

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will go deaf listning to that racket.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

never ever for any reason use gets(). Here's why.

>>Could it have something to do with using gets()?
Yes. instr can only hold 9 characters plus the null terminator and you are trying to stuff more than that into it. gets() is scribbling the overflow all over your program's memory.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am 14% Metal Head.

Sorry kid, go watch some more TRL. And stay out of the mosh pit. You'll only get yourself hurt. You, my friend, are a lamer. A RUSTY BOLT, in the metal world. A -real- metal head would kick yer ass.

Guess I didn't do very well :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

He's probably shaking his head because that racket hurts his poor ears. I do that too when I hear that awful racket :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Alcohol in moderation is not addictive -- I nibbled a little bit for roughly 40 years without getting addicted to it.

Tobacco is another matter altogether -- even just ONE cigarette can be addictive due to all the harmful chemicals tobacco companies put into their products. And I've heard its the hardest kind of addiction to overcome.

Don't know about illegal drugs -- never tried them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

this is basically what Ancient Dragon suggested from the previous thread.

you're using my original suggestion from that thread which, unfortunately, was flawed.

Yes, I think I see the bug in it. As I recall Narue pointed it out in another thread. Even this might not work 100% of the time.

void firstUpper(char *buf)
{
    while (*buf)  // continue as long as characters avail
    {
        while( isspace(*buf) || !isalpha(*buf) )
            *buf++;         // skip all spaces until next char
        *buf = toupper(*buf);   // cap first char after space
        while(*buf && !isspace(*buf) )
            *buf++;         // skip all chars until next space
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi Guys
Can Pointers In C Points To The Video Memory And Write A pixels On The Screen
Or Calls Bios 10H To Do That , What About That :
void far *scr = (void far *) 0xA0000000L

why allways there is a jerk persion
thinks him self have big humor spirit
!! be helpful or shut your ass up !!

The answer is YES pointers can do that. There were even a few books written about that, but were probably out of print many years ago.

Read this related thread.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I got an A on the assignment
Great going! :) :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Or you could use std::string's at() method, but I don't see that very often. Read this about it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where what? All I did was change what you posted and moved that while statement to the top of the menu.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oops! just define it as an int instead of a bool. bool is defined in c++, and I think the newest version of C too.

#define TRUE 1
#define FALSE 0

int done = FALSE;
do
{
    <snip>
     done = TRUE;
} while( done == FALSE && ...);

>>Error: c-project_.c(7,2):Unable to open include file 'stdbool.h'

Is there such a file?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, it is possible that using == there will get the right answer, maybe, in that particular case, because the constant string literals "hello" and "hello" could evaluate to the same pointer if the compiler is smart enough.

a == b is comparing the values of the two pointers to see if they both point to the same object. You can't count on what a compiler might or might not do with those two strings. Coding C or C++ programs does not and can not depending on what one compiler might or might not do. If you do that then the same program will probably not work correctly when compiled by a different compiler or even by the same compiler with different options.

In short: making such a comparison is just plain stupid and idiotic.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You know you're obsessed when you have more posts than the creator of the forum, and you joined three years after her.

*cough*jbennet*cough*

:)

That's not hard to do when you play those silly games in the games forum.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 32 sets status to something other than 10. That means its value is not 10 when line 40 is executed, so the loop continues.

I would use a different variable, such as bool found = false then set it to true when line 30 is executed.

bool found = false;
do
{
   <snip>
    found = true;
    // line 30 here
    <snip>
} while( found == false && !feof() );
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Apparently this is incorrect?
Yes. You are confusing std::string for C character arrays. Had a and b been declared like this then you would be right

char* a = "hello";
char* b = "hello";
// now to compare the two string you have to call strcmp()
int n = strcmp(a,b);
//if you use == to compare a and b then you will get the wrong 
//answer
if( a == b) // <<<<<< wrong when comparing two strings

Note that the term string above does NOT mean std::string but null-terminated character arrays. In the above a and b are pointers and they point to character arrays.

VernonDozier commented: Thanks. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

From the error number I'd say you are using one of the Microsoft compilers. If that is true you can easily and quickly find out the missing { or } by putting the cursor on one of the brackets and hitting Ctrl+{ or Ctrl+}. This doesn't work so well if you have { or } in quotes

VI and probably some other compiler IDEs also have similar macros to help find missing or matching brackets, braces and parentheses.

Another possibility: If you are using Microsoft compilers with precompiled headers then you have to include stdafx.h as the very first include file. If you don't have stdafx.h then disable precompiled headers. How to do that depends on the compiler version you are using.

#include "stdafx.h"
// other stuff here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why bother with strings or char as a type for choice at all. Why not just have the user enter an integer value not used in the menu to exit, say 6 or -1 or 999 or maybe 1234?

Good question, and that was suggested before in this thread. For some strange reason the OP decided to use strings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>string subChoice ="";
It isn't necessary to provide an initializer for strings because that's the default. Just string subChoice; is sufficient.

>> do we ever need to use the "compare" function
You use it when you need to know if one string is less than, equal to, or greater than the second string, such as in sorting algorithms. You could also use the < and > operators but then that might be too slow when used in if conditions because the comparison would have to be repeated.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

tellg()

seekp()

You can read all about the other fstream methods here

If you are still confused after reading the above links please explain what you are confused about.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why bother with compare() when the == operator is sufficient

if( subchoice == "100")
{

}
else 
if( subchoice == "200")
// blabla
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are not being very clear about what you want. Is species part of TREE ? What is species? is it a structure, a class, or something else.

class species
{
  // some stuff here
};

class Something
{
   Species sp;
// other stuff
};

Anything like the above? If not, then please show what you are doing

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to make a couple logic changes.

while(intChoice!=10)
    {
		cout << "INFR1100U final project: \n";
		cout << "\n***********MENU**************\n";
		cout << "_____________________________\n";
		cout << "Add/Remove Options\n";
		cout << "1. Add New User\n";
		cout << "2. Remove an Existing User\n";
		cout << "_____________________________\n";
		cout << "Modify existing users\n";
		cout << "3. Change Password\n";
		cout << "4. Change Priority\n";
		cout << "_____________________________\n";
		cout << "Print information\n";
		cout << "5. Print User Information\n";
		cout << "6. Print All user Information\n";
		cout << "_____________________________\n";
		cout << "Misc. Options\n";
		cout << "7.Write Records to Database\n";
		cout << "8. ";

			cin >> intChoice;

			switch(intChoice)
			{
				case 1:
					// Prompt user
					cout <<"\nAdd User\n";
					while (!finished)
					{
						cout << "\nPlease enter a username: ";
						cin >> UserA[index].user_id;
						cout << "\nPlease enter the users first name: ";
						cin >> UserA[index].firstName;
						cout << "\nPlease enter the users last name: ";
						cin >> UserA[index].lastName;
						cout << "\nPlease enter the users password: ";
						cin >> UserA[index].password;
					
						// User priority check
						while(!Flag)
						{
						cout << "\nPlease enter the users priority (1-7):";
						cin>> UserA[index].priority;
							if (UserA[index].priority <=7 && UserA[index].priority  >=0)
							{
								Flag=true;
							}
						 else
							{
							cout << "Error, please enter a number that equal to 0 and greater, less than 5 and equal to 5"<<endl;
							}   
						}
						// Add one to the array for the next time.
						index++;
						finished=true;
					}														
					break;
			case 2:
					
						/*
						// CHECK TO SEE IF FILE WILL OPEN 
						outStream.open("MasterUserFile.txt");

						// Attempt to open to write.. if fail, shut down!
						if (outStream.fail())
							{
								cout <<"Cannot open MasterUserFile.txt. Aborting";
								outStream.close(); …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You didn't put the menu in a loop as I suggested earlier.

bool done = false;
while( !done )
{
	// Menu
		
		cout << "INFR1100U final project: \n";
		cout << "\n***********MENU**************\n";
		cout << "_____________________________\n";
		cout << "Add/Remove Options\n";
		cout << "1. Add New User\n";
		cout << "2. Remove an Existing User\n";
// etc etc etc
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think I know what you want to do -- create a 2d linked list

typedef list<TREE> LTREE;
list<LTREE> L;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use a while loop

bool done = false;
while( !done )
{
   //show menu and execute switch statements or other stuff
}

You can use other kinds of loops too, depending on what you want it to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

function prototypes don't declare variables -- they only tell you and the compiler the data type of each parameters. Prototypes can be written without names, but only data types as in this example int foo(int, const char*, float) You will have to declare all the variables you want to pass to that function someplace before the function is actually called.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the data contains random-length records or lines then you have no other choice but to use sequential access. As always, there are a few exceptions, such as if you create an index file that contains the offsets to the beginning of each line or record, but probably goes beyond the scope of what you have in mind. Records in sequential files can not normally be changed without rewriting the entire file.

Sequential access is also used when you want to just read the contents of the entire file. This is done whether the length of each record is fixed or random. Files written to be random access can be read sequentially, but not vice versa.

Random access is used when each record or each line is exactly the same size. Then the program can calculate the exact location of any record in the file and seek to that location. You can't do that with most text files except as noted above. The program can easily change the contents of any given record because it has a fixed length.

knight fyre commented: Very clear explanation +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look at the file in Notepad or some other text editor to see if the contents are what you expect.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>toUpper()
You don't have a function by that name in the code you posted.