文件的二进制内容是:00110001 00100000,用fscanf(fp,"%d",x)或fread(x,2,1,fp)读取一个短整数,则用此两种函数读出来的结果分别是A.1 8241B.10 8241C.1 12576D.10 12576

文件的二进制内容是:00110001 00100000,用fscanf(fp,"%d",&x)或fread(&x,2,1,fp)读取一个短整数,则用此两种函数读出来的结果分别是

A.1 8241

B.10 8241

C.1 12576

D.10 12576


参考答案和解析
用文本方式打开,用fread读;用文本方式打开,用fscanf读

相关考题:

有以下程序,其功能是:以二进制 “ 写 ” 方式打开文件 d1.dat ,写入 1 ~ 100 这 100 个整数后关闭文件 。 再以二进制 “ 读 ” 方式打开文件 d1.dat , 将这 100 个整数读入 到 另一个数组 b 中 , 并打印输出 , 请填空。#include stdio.hmain(){ FILE *fp;int i,a[100],b[100];fp=fopen("d1.dat","wb");for(i=0;i100;i++) a[i]=i+1;fwrite(a,sizeof(int),100,fp);fclose(fp);fp=fopen("d1.dat", 【 20 】 );fread(b,sizeof(int),100,fp);fclose(fp);for(i=0;i100;i++) printf("%d\n",b[i]);}

读取二进制文件的函数调用形式为 :fread(buffer,size,count,fp); , 其中 buffer 代表的是A) 一个文件指针 , 指向待读取的文件B) 一个整型变量 , 代表待读取的数据的字节数C) 一个内存块的首地址 , 代表读入数据存放的地址D) 一个内存块的字节数

fread(buf,64,2,fp)的功能是 _______ 。 A.从fp文件流中读出整数64,并存放在buf中B. 从fp文件流中读出整数64和2,并存放在buf中C. 从fp文件流中读出64个字节的字符,并存放在buf中D. 从fp文件流中读出2个64个字节的字符,并存放在buf中

fscanf函数的正确调用形式是A.fscanf(fp,格式字符串,输出表列);B.fscanf(格式字符串,输出表列,fp);C.fscanf(格式字符串,文件指针,输出表列);D.fscanf(文件指针,格式字符串,输入表列);

已知在文件IN20.DAT中存有若干个(个数〈200)4位数字的正整数,函数ReadDat()的功能是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求:(1)求出这文件中共有多少个正整数totNum:(2)求㈩这些数中的各位数字之和是偶数的数的个数totCnt,以及满足此条件的这些数的算术平均值totPjz,最后调用函数WriteDat()把所求的结果输出到文件OUT20.DAT中。注意:部分源程序已给出。请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。试题程序:include〈stdio.hinciude〈conio. hdefine MAXNUM 200int xx [MAXNUM];int totNum = O; /* 文件 IN20.DAT 中共有多少个正整数 */int totCnt = 0; /* 符合条件的正整数的个数 */double totPjz = 0.0; /* 平均值 */int ReadDat (void);void Writedat (void);void CalValue (){}main ( ){int i;clrscr ();for(i = 0; i 〈 MAXNUM; i++)xx[i]= 0;if (Readdat ()){printf ("数据文件IN20.DAT 不能打开 ! \007\n");return;}CalValue ();printf ("文件IN20. DAT 中共有正整数=%d个\n", totNum);printf ("符合条件的正整数的个数=%d个\n", totCnt);printf("平均值=%.21f\n", totPjz);Writedat ();}int Readdat (void){FILE *fp;int i = 0;if((fp = fopen("IN20.DAT", "r")) == NULL)return 1;while ( ! feof (fp)){fscanf(fp, "%d,", xx[i++]);}fclose(fp);return 0;}void Writedat(void){FILE *fp;fp = fopen("OUT20.DAT", "w");fprintf(fp, "%d\n%d\n%.21f\n", totNum, totCnt, totPjz);fclose (fp);}

文件IN65.DAT中存有若干个(个数200)4位数字的正整数,函数ReadDat()是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求是:(1)求出这个文件中共有多少个正整数totNum。(2)求出这些数中的各位数字之和是奇数的个数totCnt,以及满足此条件的这些数的算术平均值totpjz。最后调用函数WriteDat()把所有结果输出到文件OUT65.DAT中。注意:部分源程序已给出。请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。include<stdio. h>include<conio. h>define MAXNUM 200int xx [MAXNUM];int totNum=0;int totCnt-0;double totPjz=0.0;int ReadDat (void);void WriteDat(void);void CalValue (void){}void main(){int i;clrscr ( );for (i=0; i<MAXNUM; i++)xx[i]=0;if (ReadDat ()){printf ("数据文件IN65.DAT不能打开!\007\n");return;}CalValue ();printf ("文件IN65. DAT中共有正整数=%d个\n", totNum);printf ("符合条件的正整数的个数=%d个n", totCnt);printf ("平均值=%.21f\n", totPj z);WriteDat ();}int ReadDat (void){FILE *fp;int i=0;if ( (fp=fopen ("IN65. DAT", "r") ) ==NULL)return 1;while ( ! feof (fp)){fscanf (fp, "%d", xx [i++] );}fclose (fp);return 0;}void WriteDat(void){FILE *fp;fp=fopen ( "OUT65. DAT", "w" );fprintf (fp, "%d\n%d\n%.2,1f\n", totNum, totCnt, totPj z);fclose (fp);}

fread(buf,32,2,fp)的功能是______。A.从fp文件流中读出整数32,存放在buf中B.从fp文件流中读出32个字节的字符,存放在buf中C.从fp文件流中读出整数32和2,存放在buf中D.从fp文件流中读出2块32个字节的字符,存放在buf中

以下程序运行后的输出结果是 。includemain(){FILE*fp;int x[6]={l,2,3,4,5,6},i;fp=fopen(“test.dat”,”wb“);fwrite(x,sizeof(int),3,fp);rewind(fp);fread(x,sizeof(int),3,f}]);for(i=0;i6;i++)printf(“%d”,x[i]);printf(“\n”);fclose(fp);}

读取二进制文件的函数调用形式为:fread(buffer,size,count,fp);,其中buffer代表的是A.一个文件指针,指向待读取的文件B.一个整型变量,代表待读取的数据的字节数C.一个内存块的首地址,代表读入数据存放的地址D.—个内存块的字节数

已知在文件IN.dat中存有若干个(少于200个)四位数字的正整数,函数ReadDat()读取这若干个正整数并存入数组number中。请编写函数CalValue(),其功能要求是:①求出文件中共有的正整数个数totNum;②求这些数右移1位后,产生的新数是奇数的数的个数totCnt以及满足此条件的这些数(右移前的值)的算术平均值totAve。最后调用函数writeDat()把所求的结果输出到OUT.dat文件中。注意:部分源程序已经给出。请勿改动主函数main()、读函数ReadDat()和写函数writeDat()的内容。include <stdio.h>include <conio. h>define MAXNUM 200int number [MAXNUM];int totNum = 0; /* 文件IN.dst 中共有的正整数个数*/int totCnt = 0; /* 符合条件的正整数的个数*/double totAve = 0.0; /* 平均值 */int ReadDat (void);void writeDat(void);void CalValue(void){}void main (){ int i;for (i=0; i<MAXNUM; i++)number [i] = 0;if (ReadDat()){ printf (" 数据文件 IN.dst 不能打开! \007\n");return;}CalValue ();printf(" 文件 IN.dst 中共有的正整数个数=%d个\n", totNum);printf (" 符合条件的正整数的个数 =%d个\n", totCnt);printf("平均值=%.2f\n", totAve);writeDat ();}int ReadDat (void){ FILE *fp;int i = 0;if ((fp = fopen("IN.dat", "r")) == NULL)return 1;while (!feof(fp))fscanf(fp, "%d,", number [i++]);fclose (fp);return 0;}void writeDat (void){ FILE *fp;fp = fopen("OUT.dat", "w");fprintf(fp, "%d\n%d\n%6.2f\n", totNum, totCnt, totAve);fclose (fp);}

已知在文件IN13.DAT中存有若干个(个数200)4位数字的正整数,函数ReadDat()的功能是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求:(1)求出该文件中共有多少个正整数totNum;(2)求这些数右移1位后,产生的新数是偶数的数的个数totCnt,以及满足此条件的这些数(右移前的值)的算术平均值totPjz,最后调用函数WriteDat()把所求的结果输出到文件OUT13.DAT中。注意:部分源程序已给出请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。试题程序:include〈stdio.hinclude〈conio.hdefine MAXNUM 200int xx [MAXNUM];int totNum = 0; /* 文件IN13.DAT 中共有多少个正整数 */int totCnt = 0; /* 符合条件的正整的个数 */double totPjz = 0.0; /* 平均值 */int ReadDat (void);void Writedat(void);void CalValue(void){}main ( ){int i;clrscr ();for(i = 0; i〈MAXNUM; i++)xx[i] = 0;if (ReadDat ()){printf ("数据文件 IN13.DAT 不能打开! \007\n");return;}CalValue ();printf("文件IN1B.DAT 中共有正整数= %d 个\n", totNum);printf("符合条件的正整数的个数= %d 个\n", totCnt);printf("平均值=%.21f\n", totPjz)Writedat ();}int ReadDat (void){FILE *fp;int i = 0;if((fp = fopen ("IN13.DAT", "r")) == NULL)return 1;while(! feof(fp)){fscanf(fp, "%d,", xx[i++]);}fclose(fp);return 0;}void WriteDat(void){FILE *fp;fp = fopen("OUT13.DAT", "w");fprintf(fp, "%d\n%d\n%.21f\n", totNum, totCnt, totPjz);fclose (fp);}

已知在文件in70.dat中存有若干个(个数<200)4位数字的正整数,函数ReadDat()是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求是:(1)求出这个文件中共有多少个正整数totNum。 (2)求这些数右移一位后,产生的新数是奇数的数的个数totCnt,以及满足此条件的这些数(右移前的值)的算术平均值totPjz。最后调用函数WriteDat()把所有结果输出到文件out70.dat中。注意:部分源程序已给出。请勿改动主函数main()、读函数ReadDat()和写函数Wiltedat()的内容。试题程序:inc lude<stdio, h>inc lude<conio, h>define MAXNUM 200int xx [MAXNUM];int totNum=0;int totCnt=0;double totPjz=0.0;int ReadDat (void);void WriteDat (void);void CalValue (void){}void main ( ){int i;clrscr ( );for ( i=0; i<MAXNUM; i++ )xx[i] =0;if (ReadDat ()){printf ( "数据文件IN70. DAT 不能打开! \007\n" );return;}CalValue ( );printf ( "文件IN70.DAT中共有正整数=%d个\n", totNum);printf ( "符合条件的正整数的个数=%d个\n", totCnt );printf ( "平均值=%.21f\n", totPjz);WriteDat ( );}int ReadDat (void){FILE *fp;int i=0;if((fp=fopen("IN70.DAT","r"))==NULL) return 1;while ( !feof (fp) ){fscanf ( fp, "%d", xx [ i++ ] );}fclose (fp);return 0;}void WriteDat (void){FILE *fp;fp=fopen("OUT70.DAT", "w");fprintf (fp, "%d\n%d\n%. 21f\n", totNum, totCnt, totPj z);fclose (fp);}

已知在文件in.dat中存有若干个(个数<200)四位非零整数,函数readdat()读取这若干个整数并存入数组xx中。请编制函数calvflue(),其功能要求:①求出该文件中共有多少个正整数totnum;②求这些数右移1~6位,产生的一系列新数中含至少一个完全平方数(某个整数的平方)的个数totcnt,以及满足此条件的这些数(右移前的值)的算术平均值totpjz,最后调用函数writedat()把所求的结果输出到文件out.dat中。部分源程序已给出。请勿改动主函数main()、读数据函数readdat()和输出数据函数writedat()的内容。include<stdio.h>include<conio.h>define MAXNUM 200int xx[MAXNUM];iht totnum=0;iht totcnt=0;double totpjz=0.0;int readdat(void);void writedat(void);void calvalue(void){}void main (){int i;clrscr ();for (i=0; i if (readdat ()){printf("Can't open the data file in.dat!\007\n");return;}calvalue ();printf ( "totnum=%d\n", totnum);printf ( "totcnt=%d\n" , totcnt );printf ( "totpj z=%. 21f\n", totpj z);writedat ();}int readdat (void){FILE *fp;int i=0;if( (fp=fopen ("in.dar", "r") )==NULL) return 1;while ( ! feof (fp))fscanf (fp, "%d, ", xx [i++] ;fclose (fp);return 0;}void writedat (void){FILE *fp;fp=fopen ( "out. dar", "w" )fprint f ( fp, "%d\n%d\n%. 21 f\n", totnum, totcnt, totpjz);fclose (fp);}

读取二进制文件的函数调用形式为:fread(buffer,size,Count,fp);,其中buffed 代表的是( )。A.一个内存块的首地址,代表读入数据存放的地址B.一个整型变量,代表待读取的数据的字节数C.一个文件指针,指向待读取的文件D.一个内存块的字节数

已知在文件IN65.DAT中存有若干个(个数<200)4位数字的正整数,函数ReadDat()是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求是: (1)求出这个文件中共有多少个正整数totNum。 (2)求出这些数中的各位数字之和是奇数的个数totCnt,以及满足此条件的这些数的算术平均值totPjz。最后调用函数WriteDat()把所有结果输出到文件 OUT65.DAT中。注意:部分源程序已给出。请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。试题程序:include<stdio. h>include<conio. h>define MAXNUM 200int xx [MAXNUM];int totNum=0;int totCnt=0;double totPjz=0.0;int ReadDat (void);void WriteDat (void)void CalValue (void){void main ( ){int i;clrscr ( );for ( i=0; i<MAXNUM; i++ )xx[i]=0;if (ReadDat ( ) ){printf ("数据文件IN65.DAT不能打开! \007\")return;}CalValue ( );printf ( "文件IN65.DAT中共有正整数=%d个\n",totNum);printf ( "符合条件的正整数的个数=%d个\n", totCnt)printf ( "平均值=%. 21f\n", totPjz);WriteDat ();}int ReadDat (void){FILE *fp;int i=0;if ( ( fp= fopen ( "IN65. DAT", "r" ) ) ==NULL)return 1;while ( ! feof (fp)){fscanf (fp, "%d", xx [i++] );}fclose (fp);return 0;}void WriteDat (void){FILE *fp;fp=fopen ("OUT65. DAT", "w" );fprint f (fp, "%d\n%d\n%. 21f\n", totNum, totCnt,totPjz);fclose (fp);}

已知在文件IN13.DAT中存有若干个(个数〈200)4位数字的正整数,函数ReadDat()的功能是读取这若干个正整数并存入数组xx中。请编制函数CalValue(),其功能要求: (1)求出该文件中共有多少个正整数totNum; (2)求这些数右移1位后,产生的新数是偶数的数的个数totCnt,以及满足此条件的这些数(右移前的值)的算术平均值totPjz,最后调用函数WriteDat()把所求的结果输出到文件OUT13.DAT中;注意:部分源程序已给出。请勿改动主函数main()、读函数ReadDat()和写函数WriteDat()的内容。试题程序:include〈stdio.hinclude〈conio.hdefine MAXNUM 200int xx [MAXNUM];int totNum = 0; /* 文件IN13.DAT 中共有多少个正整数 */int totCnt = 0; /* 符合条件的正整数的个数*/double totPjz = 0.0; /* 平均值 */int ReadDat (void);void Writedat(void);void CalValue(void){}main ( ){int i;clrscr ( );for(i = 0; i〈 MAXNUM; i++)xx[i] = 0;if (ReadDat ()){print f ( "数据文件 IN13.DAT 不能打开! \007\n" );return;}CalValue ( );printf("文件IN13.DAT 中共有正整数= %d 个\n", totNum);printf("符合条件的正整数的个数 = %d 个\n", totCnt);printf("平均值=%.21f\n", totPjz);Writedat ( );}int ReadDat (void){FILE *fp;int i = 0;if((fp = fopen ("IN13.DAT", "r") == NULL)return 1;while(! feof(fp) ){fscanf(fp, "%d,", xx[i++]);}fclose{fp);return 0;}void WriteDat(void){FILE *fp;fp = fopen("OUT13.DAT", "w");fprintf(fp, "%d\n%d\n%.21f\n", totNum, totCnt, totPjz);fclose(fp);}

读取二进制文件的函数调用形式为:fread(buffer,size,count,fp);,其中buffer代表的是( )。A.一个文件指针,指向待读取的文件B.一个整型变量,代表待读取的数据的字节数C.一个内存块的首地址,代表读人数据存放的地址D.一个内存块的字节数

若fp已正确定义为一个文件指针,d1.dat为二进制文件。请填空,以便“读取”并打开此文件:fp=fopen();。

函数ReadDat()实现从文件IN.dat中读取1000个十进制整数到数组xx中;请编写函数 Compute()分别计算出数组xx中奇数的个数odd、偶数的个数even,以及所有数的平均值aver和方差totfc的值。最后调用函数WriteDat(),把结果输出到OUT. dat文件中。计算方差的公式如下:原始数据文件存放的格式是:每行存放10个数(每个数均大于0且小于等于2000),并用逗号隔开。注意:部分源程序已经给出。请勿改动主函数main()、读函数ReadDat()和输出数据函数 WriteDat()的内容。include <stdio. h>include <stdlib. h>include <string. h>define MAX 1000int xx[MAX], odd = 0, even = 0;double aver = 0.0, totfc = 0.0;void WriteDat(void);int ReadDat(void){ FILE *fp;int i, j;if ((fp = fopen("IN. dat", "r")) == NULL)return 1;for (i=0; i<100; i++){ for (j=0; j<10; j++)fscanf(fp, "%d,", xx[i*10+j]);fscanf(fp, "\n");if (feof(fp))break;}fclose(fp);return 0;}void Compute(void){}void main (){ int i;for (i=0; i<MAX; i++)xx[i] = 0;if (ReadDat()){printf (" 数据文件 IN. dar 不能打开! \007\n");return;}Compute ( );printf("odd=%d\neven=%d\naver=%f\ntotfc=%f\n", odd, even, aver, totfc);WriteDat ();}void WriteDat(void){ FILE *fp;fp = fopen("OUT.dat", "w");fprintf(fp, "%d\n%d\n%f\n%f\n", odd, even, aver, totfc);fclose (fp);}

C语言库函数fgets (str,n,fp)的功能是______。A.从中指向的文件中读取长度n的字符串存入str指向的内存B.从fp指向的文件中读取长度不超过n-1的字符串存入str指向的内存C.从fp指向的文件中读取n个字符串存入str指向的内存D.从str读取至多n个字符到文件fp

C语言库函数fgets(str,n,fp)的功能是______。A.从fp指向的文件中读取长度n的字符串存入str指向的内存B.从fp指向的文件中读取长度不超过n-1的字符串存入str指向的内存C.从fp指向的文件中读取n个字符串存入str指向的内存D.从str读取至多n个字符到文件fp

以读写方式打开一个二进制文件fil2,fopen函数的正确的调用方式是:() A、FILE *FP; FP=fopen("fil2","r");B、FILE *FP; FP=fopen("fil2","rb");C、FILE *FP; FP=fopen("fil2","wb+");D、FILE *FP; FP=fopen("fil2","rb+");

(15)以下程序运行后的输出结果是 【15】 。#include stdio.hmain(){ FILE *fp; int x[6]={1,2,3,4,5,6},i;fp=fopen("test.dat","wb");fwrite(x,sizeof(int),3,fp);rewind(fp);fread(x,sizeof(int),3,fp);for(i=0;i6;i++) printf("%d",x[i]);printf("\n");fclose(fp);}

函数()能读取文本文件中的一行。读取二进制文件或者其他文件时,应当使用()函数。A、fgets(),fseek()B、fread(),fgets()C、fputs(),fseek()D、fgets(),fread()

哪个函数用来从文本文件里面读取一个单独的行,但是当你需要读取二进制数据或者其他格式的文件的时候,你需要使用哪个函数?()A、fgets(),fseek()B、fread(),fgets()C、fputs(),fgets()D、fgets(),fread()

以下fread函数的调用形式中,参数类型正确的是()A、fread(unsignedsize,unsignedn,char*buffer,FILE*fp)B、fread(char*buffer,unsignedsize,unsignedn,FILE*fp)C、fread(unsignedsize,unsignedn,FILE*fp,char*buffer)D、fread(FILE*fp,unsignedsize,unsignedn,char*buffer)

C语言标准库函数""fgets(string,n,fp)""的功能是()。A、从文件fp中读取长度为n的字符串存入指针string指向的内存B、从文件fp中读取长度为n-1的字符串存入指针string指向的内存C、从文件fp中读取n个字符串存入指针string指向的内存D、从文件fp中读取长度不超过长度为n-1的字符串存入指针string指向的内存

函数()能读取文本文件中的一行。读取二进制文件或者其他文件时,应当用()函数。A、fgets(), fseek()B、fread(), fgets()C、fputs(), fgets()D、fgets(), fread()E、fread(), fseek()