#include "stdio.h"
#include "string.h"
#include "stdlib.h"
int charcalculate=0;
int wordcalculate=0;
int linecalculate=0;
void calculate(char * file)
{
FILE * fp;
char a;
if((fp=fopen(file,"r"))==NULL)
{
printf("read file failed!\n");
exit(-1);
}
while(!feof(fp))
{
a=fgetc(fp);
if(a!=' '&&a!='\n'&&a!='\t'&&a!=','&&a!='.'&&a!='!'&&a!=';'&&a!='=')
charcalculate++;
if(a==' '||a=='\n'||a=='\t'||a==','||a=='.'||a=='!'||a=='='||a==';')
wordcalculate++;
if(a=='\n'||a=='\t')
linecalculate++;
}
linecalculate++;
charcalculate--;
fclose(fp);
}
int main(int argc, char* argv[])
{
FILE *fp;
calculate(argv[2]);
while(1)
{
if((fp=fopen(argv[2],"r"))==NULL)
{
printf("FileNull\n\n\n");
scanf("%s%s%s",argv[0],argv[1],argv[2]);
continue;
}
else if(!strcmp(argv[1],"-c"))
printf("File:%sCharNum:%d\n",argv[2],charcalculate);
else if(!strcmp(argv[1],"-w"))
printf("File:%sWordNum:%d\n",argv[2],wordcalculate);
else if(!strcmp(argv[1],"-l"))
printf("File:%sLineNum:%d\n",argv[2],linecalculate);
else if(!strcmp(argv[1],"exit"))
{
printf("Exit!\n");
break;
}
else
printf("NullPoint\n");
printf("\n\n");
scanf("%s%s%s",argv[0],argv[1],argv[2]);
}
return 0;
}
相关文章
- Ionic Android项目Splash设置
- WC项目要求
- vue.js及项目实战[笔记]— 05 WebPack
- 服务器---centos上前端从0到1配置项目部署
- 如何使用apache部署若依前后端分离项目
- php项目的sdk封装成composer包的创建与发版
- 【Python项目篇】【爬妹子图】
- pycharm如何新项目如何不默认创建虚拟环境(吐槽)
- Spring Boot 构建电商基础秒杀项目 (三) 通用的返回对象 & 异常处理
- vue项目安装element报错:npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency