2022年湖北专升本C语言文件模拟题
摘要:本文是2022年湖北专升本C语言文件模拟题,共有8道选择题和5道填空题,供大家参考。具体详细内容见下文。
一、单项选择题
1.若要“向文本文件尾增加数据”,在 fopen 函数中应使用的文件方式是(B)。
A) “ab+”
B) “a”
C) “ab”
D) “a+”
2.在 C 语言中,用于实现打开文件的库函数是(B)。
A) fclose()
B) fopen() C) fseek()
D) rewind()
3.若要“为读/写建立一个新的二进制文件”,在 fopen 函数中应使用的文件方式是(D)。
A) “w+”
B) “rb+”
C) “ab+”
D) “wb+”
4.若在 fopen 函数中使用文件的方式是“ab”,该方式的含义是( B)。
A) 为读/写打开一个文件
B) 向二进制文件尾增加数据 C) 为输出打开一个文本文件
D) 为读/写建立一个新的二进制文件
5.若在 fopen 函数中使用文件的方式是“r”,该方式的含义是( A)。
A) 为输入(读)打开一个文本文件
B) 为输出(写)打开一个文本文件
C) 为读/写打开一个文本文件
D)为读/写建立一个新的二进制文件
6.在 C 程序中,可把整型数以二进制形式存放到文件中的函数是( C )。
A) fprintf 函数 B) fread 函数 C) fwrite 函数 D) fputc 函数
7.若 fp 是指向某文件的指针,且已读到此文件末尾,则库函数 feof(fp)的返回值是( C)。
A) EOF
B) 0
C) 非零值
D) NULL
8.下面的程序执行后,文件 test.t 中的内容是( A)。
#include
void fun(char *fname., char *st)
{FILE *myf; int i;
myf=fopen(fname, "w");
for(i=0;i<strlen(st);i++)
fputc(st[i], myf);
fclose (myf);
}
main()
{fun("test.t", "new world"); fun("test.t", "hello,";)
A) hello,
B) new worldhello,
C) new world
D) hello, rld
二、填空题
1.下面程序把从终端读入的 10 个整数以二进制方式写到一个名为 bi.dat 的新文件中。请填空。
#include
FILE *fp;
{int i, j;
if((fp=fopen (bi.dat,“wb”))= =NULL) exit(0);
for(i=0; i<10; i++)
{scanf(“%d”, &j);
fwrite(&j, sizeof(int), 1, fp);
}
fclose(fp);
}
2.以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换成大写字母,输出到文件 test.txt 中,然后从该文件读出字符串并显示出来。请填空。
#include
main()
{FILE *fp;
char str[100];
int i=0;
if((fp=fopen(“test.txt”," w "))= =NULL)
{printf(“Can’t open this file.\n”); exit(0);}
printf(“Input a string: \n”); gets (str);
while (str[i])
{if(str[i]>=‘a’&&str[i]<=‘z’)
str[i]=str[i]-32;
fputc(str[i], fp);
i++;
}
fclose (fp);
fp=fopen(“test.txt”,"r");
fgets(str, 100, fp);
printf(“%s\n”, str);
fclose (fp);
}
3.用以下程序把从键盘输入的字符存放到一个文件中,用字符#作为结束符,请按题意要求填空完善程序。
#include
main()
{FILE *fp;
char ch, fname[10];
printf(“Input the name of file:\n”);
gets (fname);
if((fp=fopen( fname,"w"))= =NULL)
{printf(“can’t open file\n”);
exist(0);
}
while((ch=getchar())!=‘#’)
fputc (ch,fp);
fclose (fp);
}
4.下面程序用来统计文件中字符的个数,请填空。
#include
main()
{FILE *fp;
long num=0;
if((fp=fopen(“fname.dat”, “r”))= =NULL)
{printf(“can’t open file\n”);
exit(0);
}
while (!feof(fp))
{fgetc (fp); num++;}
printf(“num=%d\n”, num);
fclose (fp);
}
5.以下程序中用户由键盘输入一个文件名,然后输入一串字符(用#结束输入)存放到此文件中,形成文本文件,并将字符的个数写到文件尾部。请填空。
#include
main( )
{FILE *fp;
char ch,fname[32]; int count=0;
printf("Input the filename :"); scanf("%s",fname);
if((fp=fopen(fname,"w+"))==NULL)
{printf("Can't open file:%s\n",fname); exit(0);}
printf("Enter data:\n");
while((ch=getchar())!="#") {fputc(ch,fp); count++;}
fprintf( fp ,"\n%d\n",count);
fclose(fp);
延伸阅读
- 2022年湖北专升本电路模拟题(四)
- 2022年湖北专升本电路模拟题(三)
- 2022年湖北专升本电路模拟题(二)
- 2022年湖北专升本电路模拟题(一)
- 2022年湖北专升本高等数学模拟题(三)
- 2022年湖北专升本高等数学模拟题(二)
专升本微信公众号
扫码添加
专升本备考资料免费领取
去领取
扫描二维码