#include %26lt;stdio.h%26gt;
int main(void)
{
FILE *reportfile;
reportfile = fopen("E:\\report.txt","wt");
if (reportfile = NULL)
{
printf("Report file open failed");
fflush(stdin);
printf("press any ");
}
else
{
printf ("hello are you working");
}
return 0;
}
This code is only a piece of my program if you need the whole program let me know. My question is the following i need to write the output to a file not to screen shots. This is what i am doing right now and i am opening the file correctly but i am not sending any output to the file what do i need to use to send the output to the file. And what about if i want to use i function can show help with both questions one without a function and the other one with the function calling the file as a pointer.
I need a hint on a c program?
look at fprintf. Probably that is what you are looking for since you use fopen.
If you use open instead, look at write.
Reply:visit by blog
http://codesbyshariq.blogspot.com for more hints.
Reply:I don't understand your last sentence, but if you want to write to a file using a FILE *, try fwrite().
Reply:#include %26lt;stdio.h%26gt;
int main(void)
{
FILE *reportfile;
reportfile = fopen("E:\\report.txt","wt");
if (reportfile = NULL)
{
printf("Report file open failed");
fflush(stdin);
printf("press any ");
}
else
{
// the next line sends output to the open file referenced by reportfile
fprintf (reportfile, "hello are you working\n");
fclose(reportfile); // Must close file when finished with it.
}
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment