下面的程序用变量count统计文件中小写字母的个数。
#include
#include
int main(void)
{ FILE *fp; char a;
int count=0;
if((fp=fopen("d:letter.txt",【 】))==NULL)
{ printf("can not open file ");
exit(0);}
while(!feof(fp))
{ 【 】
if(【 】) count++;
}
fclose(fp);
printf("字符个数是:%d ",count);
return 0;
}
【】中应依次填入( )。
#include
#include
int main(void)
{ FILE *fp; char a;
int count=0;
if((fp=fopen("d:letter.txt",【 】))==NULL)
{ printf("can not open file ");
exit(0);}
while(!feof(fp))
{ 【 】
if(【 】) count++;
}
fclose(fp);
printf("字符个数是:%d ",count);
return 0;
}
【】中应依次填入( )。
举一反三
- 以下程序中用户由键盘输入一个文件名,然后输入一串字符(用#结束输入)存放到此文件文件中形成文本文件并将字符的个数写到文件尾部,请填空。#include"stdio.h"#include"stdlib.h"voidmain(){FILE*fp;charch,fname[32];intcount=0;printf("Inputthefilename:");scanf("%s",fname);if((fp=fopen())==NULL){printf("Can'topenfile:%s ",fname);exit(0);}getchar();printf("Enterdata:");while((ch=getchar())!='#'){fputc(ch,fp);count++;}fprintf(," %d ",count);fclose(fp);}
- 下面程序的输出结果是________。#include<;stdio.h>;int main( ){ FILE *fp; int n,a[2]={65,66}; char ch; fp=fopen("d.dat","w"); fprintf(fp,"%d%d",a[0],a[1]); fclose(fp); fp=fopen("d.dat","r"); fscanf(fp,"%c",&ch); n=ch; while(n!=0){printf("%d",n%10);n=n/10;} fclose(fp); return 0;}
- 有以下程序 #include #include main() { FILE*fp; charch,str[5]; if((fp=fopen('file.txt','wb+'))==NULL) { printf('error! '); exit(0); } ch=getchar(); while(ch!='!') { fputc(ch,fp); ch=getchar(); } rewind(fp); fgets(str,4,fp); while(!feof(fp)) { puts(str); fgets(str,4,fp); } fclose(fp); } 程序运行时输入:c:est!,则程序的输出结果是
- 请在______填上适当内容,完成如下程序:int main(void){ FILE * fp; char str[10]; scanf("%s",str); if ((fp=fopen(str,"w"))______ NULL){ fprintf(fp,“%s”,str); fclose(fp); } return 0; }
- 以下程序运行后,data.txt文件中的内容是() #include "stdio.h" int main() {FILE *fp; int a=15,b; fp=fopen("d:\data.txt","w"); fprintf(fp,"%d,",a); b=a+10; fprintf(fp,"%d ",b); fclose(fp); getch(); return 0; }