problem with C
Posted: Thu Nov 18, 2004 7:54 pm
#include<stdio.h>
int main()
{
FILE *fp;
char xp,test;
test=0;
printf("please input a number:\n");
scanf("%d",&test);
if((fp=fopen("zhou.h","w"))!=NULL)
??? fwrite(&test,sizeof(char),1,fp);
fclose(fp);
if((fp=fopen("zhou.h","r"))!=NULL)
fread(&xp,sizeof(char),1,fp);
printf("xp=%d\n",xp);
printf("test=%d\n",test);
fclose(fp);
return 0;
}
please run this program, if input 26, that the value of 'xp' is zero, why?
int main()
{
FILE *fp;
char xp,test;
test=0;
printf("please input a number:\n");
scanf("%d",&test);
if((fp=fopen("zhou.h","w"))!=NULL)
??? fwrite(&test,sizeof(char),1,fp);
fclose(fp);
if((fp=fopen("zhou.h","r"))!=NULL)
fread(&xp,sizeof(char),1,fp);
printf("xp=%d\n",xp);
printf("test=%d\n",test);
fclose(fp);
return 0;
}
please run this program, if input 26, that the value of 'xp' is zero, why?