Hi I am trying to write a structure to a file. Below is the code.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*structure*/
struct student
{
char name[10];
char space[1];
char rollno[5];
}head_rec;
/*main*/
void main()
{
FILE *fout;
if(fout=fopen("output.txt","w")==NULL)
{
printf("Cannot open the file to write");
exit;
}
memset(&head_rec,'\0',sizeof(struct student);
sprint(head_rec.name,"SOUMYA",6);
memset(head_rec.space,' ',1);
memset(head_rec.rollno,'\0',sizeof(head_rec.rollno);
sprint(head_rec.rollno,"0000",4);
head_rec.rollno[4]='\0';
fwrite(&head_rec,sizeof(struct student),1,fout);
}
Output:
SOUMYA 0000^@
How to get rid of that last character?