//请修改指定区域中的程序错误实现所需功能, //不能修改其他代码。 #include<stdio.h> void main() { //---------------错误开始-------------- FILE fp; long cnt=0; char c,filename[20]; void createfile(); createfile(); scanf("%s",filename); fp=fopen(filename,"w"); while(feof(fp)) //---------------错误结束-------------- { c=fgetc(fp); if(c>='0'&&c<='9') cnt++; } printf("%ld",cnt); fclose(fp); }
时间: 2023-08-27 16:18:48 浏览: 31
#include<stdio.h>
void createfile(); // 声明createfile函数
int main() { // main函数返回值修改为int型
FILE *fp; // 修改fp为指向文件的指针
long cnt=0;
char c, filename[20];
createfile(); // 调用createfile函数
scanf("%s",filename);
fp=fopen(filename,"r"); // 以只读方式打开文件
if(fp == NULL) { // 判断文件是否打开成功
printf("文件打开失败!\n");
return 0;
}
while((c=fgetc(fp)) != EOF) { // 修改while循环条件
if(c>='0'&&c<='9')
cnt++;
}
printf("%ld",cnt);
fclose(fp);
return 0;
}
void createfile() { // 定义createfile函数
FILE *fp;
char filename[20];
scanf("%s", filename);
fp=fopen(filename,"w"); // 以只写方式打开文件
fprintf(fp, "1234abcd5678efgh"); // 写入字符串到文件中
fclose(fp);
}
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)