“输入一text, 然后输出其单词个数”,main函数是在哪里错了?
我认为子程序没有问题, 可能是main程序有误,请指教。#include<stdio.h>
int main(void)
{
void readLine(char buffer[]);
int countWord(char string[]), totalWords=0;
char text1[81];
printf("Type in your text:\n");
readLine(text1);
printf("%s\n",text1 );
totalWords=countWord(text1);
printf("the word number of this text is %i\n", totalWords );
return 0;
}
void readLine(char buffer[]) /*读入text*/
{
char charector;
int i;
for(i=0; buffer[i]!='\0'; i++)
{
charector=getchar();
buffer[i]=charector;
}
buffer[i-1]='\0';
}
int alphabetic(char c) /*以下是计算单词数目程序*/
{
if( (c>='a'&&c<='z') || (c>='A'&&c<='B') )
return 1;
else return 0;
}
int countWord(char string[])
{
int alphabetic(char c),
Lookingforword=1, i, wordcount=0;
for(i=0; string[i]!=0; i++)
{
if(alphabetic(string[i]))
{
if(Lookingforword==1)
{ wordcount++;
Lookingforword=0;}
}else Lookingforword=1;
}
return wordcount;
}