程序补充:关于文件操作

来源:百度知道 编辑:UC知道 时间:2024/05/29 02:33:46
统计当前目录下文本文件data.txt中数字字符(‘0’到‘9’)出现的次数。
# include <stdio.h>
void main()
{ ______;
char ch;int count=0;
if((fp=fopen("data.txt","r"))==NULL)
{printf("不能打开文件data.txt!\n");
exit(0);
}
while((ch=______(fp))!=EOF)
if(ch<='9'&&ch>='0')count++;
printf("%d",count);
fclose(fp);
}

--------------------

mark cboomup

# include <stdio.h>
# include <stdlib.h>
void main()
{ FILE * fp;
char ch;int count=0;
if((fp=fopen("data.txt","r"))==NULL)
{printf("不能打开文件data.txt!\n");
exit(0);
}
while((ch=getc(fp))!=EOF)
if(ch<='9'&&ch>='0')count++;
printf("%d",count);
fclose(fp);
}

FILE *fp;
fgetc