下列程序的运行结果为。#include int main(void){FILE *fp;int i;char t, str[]="abcd";fp=fopen("abc.dat","wb+");for(i=0;i<4;i++)fwrite(&str[i],1,1,fp);fseek(fp,-3L,2);fread(&t,1,1,fp);fclose(fp);printf("%c\n",t);return 0;}
查看答案
下列程序的运行结果为。#includeint main(void){FILE *fp;int i, k=0,n=0;fp=fopen("d1.dat","w");for(i=1;i<4;i++)fprintf(fp,"%d",++i);fclose(fp);fp=fopen("d1.dat","r");fscanf(fp,"%d",&k);printf("%d\n%d\n",k,n);fclose(fp);return 0;}
下列程序的运行结果为。#include#includeint main(void){FILE *fp;float sum=0.0,x;int i;float y[4]={-12.1,13.2,-14.3,15.4};if((fp=fopen("data1.dat","wb"))==NULL)exit(0);for(i=0; i<4; i++)fwrite(&y[i],4,1,fp);fclose(fp);if((fp=fopen("data1.dat","rb"))==NULL)exit(0);for(i=0;i<4;i++,i++){fread(&x,4,1,fp);sum+=x;}printf("sum=%.1f\n",sum);fclose(fp);return 0;}
下列程序的运行结果为。#includeintmain(void){FILE*fp;inta[10]={11,22,33,44,55,66,77,88,99,100};intb[6],i;fp=fopen("test.dat","wb");fwrite(a,sizeof(int),10,fp);fclose(fp);fp=fopen("test.dat","rb");fread(b,sizeof(int),6,fp);fread(b+2,sizeof(int),4,fp);fclose(fp);for(i=0;i<6;i++)printf("%d",b[i]);return0;}
函数fgets(str,n,fp)的功能是从文件读入 个字符,存放到字符数组str中。如果该函数调用成功,将返回 ;否则,返回NULL。