代码拉取完成,页面将自动刷新
<<<<<<< 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。