C语言-文件操作-11

C语言-文件操作-11 题目编写一个程序以一个字符和任意文件名作为命令行参数。如果字符后面没用参数该程序读取标准输入否则程序依次打开每个文件并报告灭个文件中出现的次数。文件名和字符本身也要一同报告。程序应包含错误检查以确定参数数量是否正确和是否能打开文件。如果无法打开文件程序应该报告这一情况然后继续处理下一个文件。源代码#include stdio.h #include ctype.h #include stdlib.h int main(int argc,char * argv[]){ FILE * fp; char ch; int ch_num0; int file_location 2; if(argc 2){ printf(命令行参数缺失\n); exit(EXIT_FAILURE); } if(argc 3){ printf(请输入字符: ); while((ch getc(stdin)) ! EOF){ if(ch argv[1][0]) ch_num; } printf(输入的字符串中有字符 %c %d 个,argv[1][0],ch_num); exit(EXIT_SUCCESS); } while(file_location ! argc){ ch_num 0; if((fp fopen(argv[file_location],r)) NULL){ printf(文件 %s 打开失败\n,argv[file_location]); file_location; continue; } while((ch getc(fp)) ! EOF){ if(ch argv[1][0]) ch_num; } printf(文件 %s 有字符 %c %d 个\n,argv[file_location],argv[1][0],ch_num); file_location; fclose(fp); } return 0; }演示效果如果朋友你感觉文章的内容对你有帮助可以点赞关注文章和专栏以及关注我哈嘿嘿嘿我会定期更新文章的谢谢朋友你的支持哈