Home Forums C Programming Some problems in C++ Re: Re: Some problems in C++


The first function “read” looks ok to output the file data one word per line ,except I would probably pass the user’s name as a parameter instead of a global variable :

void read( char * userName );

the second function for adding data to a file ( not sure why you used both fstream.h and stdio.h for file input / output in the same program ( ? ) ) seems to have some problems. First I would allocate an array of the proper size and use strcpy ( string.h ) to copy the data.

char yazi [ MAX_SIZE ];
strcpy ( yazi , sendText );

Next , you should take read() and write() out of the conditional or the program will never end :

if ( sendtext )
FILE * pFile;
char yazi[] = {sendtext , 'n'};
pFile = fopen ( "msngr.txt" , "a+" );
fwrite (yazi , 1 , sizeof(yazi) , pFile );
fclose (pFile);
read(); //take these out!

thats what I see so far…..