WC一个简单的文件检测系统 用c语言实现 不多说 上代码
#include<stdio.h>
#include<stdlib.h>
#include <io.h>
#include <string.h>
void jichu(FILE *fp1){
int characters,lines,words,space,state;
characters=words=state=space=;
lines=;
char c;
while(( c=fgetc(fp1))!=EOF){
fputc(c,stdout);
characters++;
if(c=='\n'){
state=;
lines++;
}if(c==' '){
state=;
space++;
}else{
if(state==){
state=;
words++;
}
}
}
printf("\n%d %d %d %d\n",words,lines,characters,space);
}
int klines=,dlines=,zlines=,sum=,sum1=;
void kuozhan(FILE *fp1,int sum){
char c;
while(( c=fgetc(fp1))!=EOF){
if(c!='\n'){
if(c!=' '){
sum++;
}if(c=='/'||c=='*'){
sum1++;
}
}else{
if(sum<=){
klines++;sum=;
}
if(sum>=&&sum1==){
dlines++;
}if(sum1==){
zlines++;
sum1=;
}
}
}
printf("%d %d %d\n",klines,dlines,zlines);
}
void dg(){
long Handle;
struct _finddata_t FileInfo;
//system("mode con: CP SELECT=936");
if((Handle=_findfirst("D:\\*.txt",&FileInfo))==-1L)
printf("没有匹配项目\n");
else{
printf("%s\n",FileInfo.name);
while(_findnext(Handle,&FileInfo)==)
printf("%s\n",FileInfo.name);
_findclose(Handle);
}
}
int main(){
FILE *fp1;
fp1=fopen("d:\\T1.txt","r");
printf("请输入c,s,a \n");
char c;
scanf("%c",&c);
if(c=='c'){
jichu(fp1);
}if(c=='s'){
dg();
}if(c=='a'){
kuozhan(fp1,sum);
}
fclose(fp1); }
由于最近事太多 所以项目完成不太理想 还有很多细节的地方要修改~anyway~等周末有空再更新把~