首页 > 代码库 > WC项目
WC项目
#include <stdio.h>
#include<Windows.h>
int isrand(char c, int &randnum)//判断是否换行
{
if (c == ‘\n‘)
{
randnum++;
if (randnum == 1)
return 1;
else
return 0;
}
else
{
if (randnum>0)
randnum = 0;
return 0;
}
}
int isWord(char c, int &wordnum)//判断是否单词
{
if ((c >= ‘a‘&&c <= ‘z‘) || (c >= ‘A‘&&c <= ‘Z‘))
{
wordnum++;
if (wordnum == 1)
return 1;
else
return 0;
}
else
{
if (wordnum>0)
wordnum = 0;
return 0;
}
}
int ischaracter(char c)//判断是否字符
{
if ((c<‘0‘ || c>‘9‘) && c != ‘\n‘)
return 1;
else
return 0;
}
int main()
{
int rand = 0, word = 0, character = 0;//初始化总行数 ,单词数 ,字符数
int randnum = 0, wordnum = 0;//randnum为行数 ,wordnum为次数
char c;
printf("请输入要检测的程序\n");
while (randnum<2)//如果不是空行则循环
{
c = getchar();
rand += isrand(c, randnum);
word += isWord(c, wordnum);
character += ischaracter(c);
}
printf("总行数:%d\n", rand);
printf("单词数:%d\n", word);
printf("字符数:%d", character);
system("pause");
return 0;
}
WC项目