Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

fwrite (junk characters)

807578Feb 13 2010 — edited Feb 14 2010
Hi,

I have problem with this code it put the junk data in output file :

#include <stdio.h>
#include <string.h>
int main (int argc, char *arg[])
{
char data[6];
char fil_date[20];
memset ( data,"ALTA",5);
fp = fopen("abc.txt","w+");
sprintf(fil_data,"%5s-----hello",data);
fwrite(&fil_data,sizeof(fil_data),fp);
//fprintf(fp,"%5s---hello",data);
}

output file(abc.txt has data lik ):
ALTA^@^@^@

---- And if i remove the comment before fprintf() and comment the fwrite()
---- then the program is creating output file without junk characters.

why is this fwrite() adding junk in output file..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2010
Added on Feb 13 2010
5 comments
798 views