|
-
October 18th, 2004, 08:51 PM
#1
The problem with fprintf
I write some codes below
FILE * fp;
int j=0;
char FileName[100]={0};
sprintf(FileName,"C:\\mttemp.txt");
if((fp=fopen(FileName,"a+"))!=NULL)
{
j=fprintf(fp,"hello\n");
fclose(fp);
}
After execute it , var j is 6,and the new file C:\mttemp.txt was created,but there is nothing in the file C:\mttemp.txt.
What's wrong?
-
October 19th, 2004, 02:49 AM
#2
Re: The problem with fprintf
Hi.
Your code works fine on my system. When do you view the file? You have to wait until the call to fclose( fp ) is finished. Since you used buffered I/O the text is first written to some buffer and not directly to the file. Check the contents of your file AFTER fclose(fp).
Peter
-
October 19th, 2004, 05:21 AM
#3
Re: The problem with fprintf
...or call fflush after fprintf.
-
October 20th, 2004, 08:11 PM
#4
Re: The problem with fprintf
Thanks very much, Peter and marsh. i have resolved the problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|