Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send data to text file after read from pipe?

Status
Not open for further replies.

AoifeC

Programmer
Apr 12, 2002
7
IE
I'm a VC++ newbie!

I am trying to read from a pipe and then write the data to a textfile. I can read from the pipe and put the data into my dialog but it won't write the data to a text file. I know that it is opening the file and it does write the test "hello's" but not data from the pipe.

Here is the code that reads from the pipe:

FILE *stream;
char buffer[1024];
.
.
.
stream = fopen( "number", "w" );
fprintf( stream, "Hello\n"); //This goes to the text file

//Read from the pipe
ReadFile(hReadPipe, buffer, 1024, &bytesread, NULL);
fprintf( stream, "Hello2 %s \n", buffer); //Hello2 goes to the text file but nothing else

//send the message from the pipe to the edit box.
SendDlgItemMessage(hDlg, EDIT1, EM_SETSEL, -1, 0);
SendDlgItemMessage(hDlg, EDIT1, EM_REPLACESEL, FALSE, (LPARAM)buffer);

fclose( stream );



Thanks.
 
I think you'll find that since you are using the "w" parameter to your fopen() and the file exists, the contents of the file are being destroyed, since this is the default action with the "w" parameter when the file exists.

So there is now nothing in the file to read hence nothing in the stream to write.

Use r+ instead since the file exists or a+ if you want to append the data to the end of the file.

HTH

William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top