代码拉取完成,页面将自动刷新
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int zifushu(FILE *fp);
int cishu(FILE *fp);
int line(FILE *fp);
int main(int argc,char *argv[])
{
char filename[20];
printf("Please input you want to open the file name:\n");
gets(filename);
FILE *fp;
if((fp=fopen(filename,"r"))==NULL){
printf("cannot open file\n");
exit(0);
}
char a;
int count=0;
printf("请输入一个字符:(c统计字符数/w统计单词数/l统计行数)\n");
scanf("%c",&a);
if(a=='c'){
count=zifushu(fp);
}else if(a=='w'){
count=cishu(fp);
}else if(a=='l'){
count=line(fp);
}else{
printf("请输入正确的命令字符\n");
fclose(fp);
return 0;
}
printf("%d",count);
fclose(fp);
return 0;
}
int zifushu(FILE *fp){
/*FILE *fp;
if(fp=fopen(file.c,"r")==NULL){
printf("cannot open file\n");
exit(0);
}*/
char c;
int count=0;
while(!feof(fp)){
c=fgetc(fp);
if(c>=0&&c<=127){
count++;
}
}
//fclose(fp);
return count;
// printf("%d",count);
}
int cishu(FILE *fp){
/*FILE *fp;
if(fp=fopen(file.c,"r")==NULL){
printf("cannot open file\n");
exit(0);
}*/
char c;
int count=0;
while(!feof(fp)){
c=fgetc(fp);
if((c>='A'&&c<='Z')||(c>='a'&&c<='z')) count++;
}
//fclose(fp);
return count;
// printf("%d",count);
}
int line(FILE *fp){
/*FILE *fp;
if(fp=fopen(file.c,"r")==NULL){
printf("cannot open file\n");
exit(0);
}*/
char c;
int count=0;
while(!feof(fp)){
c=fgetc(fp);
if(c=='\n') count++;
}
//fclose(fp);
return count;
// printf("%d",count);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。