Thursday, July 30, 2009

My c program printing some unwanted data to a text file but it printing currect to output screen?

iam using fprintf(). from where printf() followed by fprintf() i am getting currect data on my screen but where it is writing wrong data to text file. for this i am using Turbo C.

My c program printing some unwanted data to a text file but it printing currect to output screen?
Please post some of the code so i can look and find any errors.





For starters, you might try using fprintf() for both the screen AND the file output. Did you know?





You can print to screen like this:





fprintf(stdout, "This will print on the screen...\n");





"stdout" is defined in stdio.h ... so you must include it.





This way, using the same function for both screen and the file output, just might help you to see the problem...what you might have missed.





#include %26lt;stdio.h%26gt;





FILE *myfile;





fprintf(stdout, "This is some program...\n"); //to screen


fprintf(myfile, "This is some program...\n"); //to file





...try to keep them identical (except for the output destination, of course).
Reply:hello


thnx for ur answer. i got solution for that by opening the file in binary format.


that is fopen("file","rb");


this will open the file in binary format rather than text format. Report It



No comments:

Post a Comment