- 以下程序执行后输出结果是
#include <stdio.h>
int main()
{
FILE *fp;
int i,k=0,n=0;
fp=fopen("d1.dat","w");
if (fp == NULL)
{
printf("cannot open the file.\n");
exit(0);
}
for(i=1;i<4;i++)
{
fprintf(fp,"%d",i);
}
fclose(fp);
fp=fopen("d1.dat","r");
if (fp == NULL)
{
printf("cannot open infile.\n");
exit(0);
}
fscanf(fp,"%d%d",&k,&n);
printf("%d %d\n",k,n);
fclose(fp);
return 0;
}
123 0
-
若fp已正确定义并指向某个文件,当未遇到该文件结束标志时函数feof(fp)的值为 0
如果文件结束,则返回非0值,否则返回0 -
设有以下结构类型,并且结构数组student中的元素都已有值,若要将这些元素写到硬盘文件fp中,以下形式错误的是:?
struct st
{
char name[8];
int num;
float s[4];
} student[50];
A.fwrite(student, sizeof(struct st), 50, fp);
B.for (i = 0; i < 50; i++) fwrite(student, sizeof(struct st), 1, fp);
C.fwrite(student, 25 * sizeof(struct st), 2, fp);
D.fwrite(student, 50 * sizeof(struct st), 1, fp);