有如下定义:struct st{ int a; float b;} x[ 10];FILE *fp;若文件己正确打开,且数组x的10个元素均己赋值,以下将数组元素写到文件中的语句错误的是()。
A. for(i=0; i B. fwrile(x,10 * sizeof( struct st) ,1 ,fp);
C. fwrite(x,sizeof(struct st) ,10,fp);
D. for(i =0; i < 10 ;i +4 ) fwrite(&x[i], sizeof (struct st) ,1 ,fp);
有以下程序#include main(){ FILE *fp;int a[10]={l,2,3,0,0},i;fp = fopen("d2.dat","wb");fwrite(a,sizeof(int),5,fp);fwrite(a,sizeof(int),5,fp);fclose(fp);fp = fopen("d2.dat","rb");fread(a,sizeof(int), 10,fp);fclose(fp);for (i=0; i<10; i++) printf("%d,",a[i]);}程序的运行结果是()。
A. 1, 2, 3, 0, 0, 0, 0, 0, 0, 0,
B. 1, 2, 3, 1, 2, 3, 0, 0, 0, 0,
C. 123 , 0, 0, 0, 0, 123 , 0, 0, 0, 0,
D. 1, 2, 3, 0, 0, 1, 2, 3, 0, 0,
有以下程序:#include < stdio. h >main(){ FILE *fp;int i, a[6] = {1,2,3,4,5,6} , k;fp = fopen(" data, dat" , " w + b");fwrite(&a[0] , sizeof(int), 1, fp);for (i = 1; i <6; i ++ ) { fseek(fp, OL, 0);fread(&k, sizeof( int) , 1, fp);fseek(fp, OL, 0);a[i] +=k;fwrite(&a[i], sizeof(int), 1, fp);}rewind (fp);fread(&k, sizeof( int) , 1, fp);fclose(fp);printf( "%d\n" , k);}程序的运行结果是()。
A. 21
B. 6
C. 123456
D. 11