先上代码
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
double _COUNT_LETTERS_AND_WOEDS(void);
int main(void)
{
printf("%5f \n",_COUNT_LETTERS_AND_WORDS());
return 0;
}
double _COUNT_LETTERS_AND_WORDS(void)
{
char ch;
double words = 0;
double letters = 0;
bool inword = false;
while((ch = getchar()) != EOF)
{
if((!isspace(ch) && !inword) && !ispunct(ch))
{
words++;
inword = true;
}
if((isspace(ch) && inword) && ispunct(ch))
inword = false;
if(!isspace(ch) && !ispunct(ch))
letters++;
}
return letters/words;
}
这是一个计算字符与单词的程序 函数返回每个单词的平均字符数。
我不太明白那个报错函数类型冲突是为什么?还有函数的隐式声明?