fwrite writes only name from the structure emp and rest of them are written garbage value to the file. so it would be really great if any one of you can help me out
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
FILE *fp;
char another,choice,useme;
struct emp
{
char name[40];
int age[10];
int bs[10];
};
struct emp e;
int stsize;
fp=fopen("emp.dat","rb+");
if(fp==NULL)
{
fp=fopen("emp.dat","wb+");
puts("cannot open file");
exit(1);
}
stsize=sizeof(struct emp);
while(1){
printf("\n 1. add records");
printf("\n 2. list records");
printf("\nyour choice\n");
choice=getchar();
switch(choice)
{
case'1' :
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
printf("\n Enter name");
scanf("%s",e.name);
printf("\n enter age\n");
scanf("%s",e.age);
printf("\n enter salary\n");
scanf("%s",e.bs);
fwrite(&e,stsize,1,fp);
fflush(stdin);
printf("\n add another record(y/n)");
another=getchar();
}
break;
case '0':
fclose(fp);
exit(0);
}
}
}