1 Star 0 Fork 0

奕m/WordCount

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
WordCount.c 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
奕m 提交于 2021-05-09 13:07 . first commit
<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> a9fab65 (first commit)
>>>>>>> 8b86948 (first commit)
>>>>>>> 6da8f88 (first commit)
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int countc(char*file);
int countw(char*file);
int main(int argc, char *argv[])
{
char data;
FILE *fb=fopen(argv[2],"r");
if(!fb)
{
printf("文件读取失败\n");
return -1;
}
if(!strcmp(argv[1],"-c"))
{
countc(argv[2]);
}
else if(!strcmp(argv[1],"-w"))
{
countw(argv[2]);
}
else
{
printf("输入出错\n");
}
return 0;
}
int countc(char*file)
{
FILE *fb;
fb=fopen(file,"r");
char temp;
int num = 0;
temp = fgetc(fb);
while( temp != EOF )
{
temp = fgetc(fb);
num++;
}
printf("该文本文件的字符数为:%d\n",num);
}
int countw(char*file)
{
FILE *fb=fopen(file,"r");
int w = 0;
char a = fgetc(fb);
while(a!= EOF)
{
if((a >='a' && a <='z') || ( a >='A' && a <='Z') || ( a >='0' && a <='9'))
{
w++;
while((a >='a' && a <='z') || ( a >='A' && a <='Z') || ( a >='0' && a <='9'))
{
a =fgetc(fb);
}
}
else
{
a =fgetc(fb);
}
}
printf("该文本文件的单词数为:%d\n",w);
}
<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
=======
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(int argc, char* argv[])
{
int counts = 0;
char c;
FILE* fp = fopen(argv[2], "r");
if (fp == NULL)
{
printf("没有读取到文件\n");
return 0;
}
if (argv[1][1] == 'w') {
while ((c = fgetc(fp)) != EOF) {
if (c == ' ' || c == ',') {
counts++;
}
}
printf("单词数:%d\n", counts + 1);
}
else if (argv[1][1] == 'c') {
while ((c = fgetc(fp)) != EOF) {
counts++;
}
printf("字符数:%d\n", counts);
}
fclose(fp);
return 0;
}
>>>>>>> 7cbbbcb (first commit)
>>>>>>> a9fab65 (first commit)
>>>>>>> 8b86948 (first commit)
>>>>>>> 6da8f88 (first commit)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cym666666/word-count.git
git@gitee.com:cym666666/word-count.git
cym666666
word-count
WordCount
master

搜索帮助