Home › Forums › C Programming › Some problems in C++ › Re: Re: Some problems in C++
January 21, 2009 at 9:35 pm
#3506
GWILouisaxwzkla
Participant
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 :
1 2 3 | <br /> void read( char * userName );<br /> |
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.
1 2 3 4 | <br /> char yazi [ MAX_SIZE ];<br /> strcpy ( yazi , sendText );<br /> |
Next , you should take read() and write() out of the conditional or the program will never end :
1 2 3 4 5 6 7 8 9 10 11 12 13 | <br /> if ( sendtext )<br /> {<br /> FILE * pFile;<br /> char yazi[] = {sendtext , 'n'};<br /> pFile = fopen ( "msngr.txt" , "a+" );<br /> fwrite (yazi , 1 , sizeof(yazi) , pFile );<br /> fclose (pFile);<br /> read(); //take these out!<br /> write();<br /> }<br /> <br /> |
thats what I see so far…..