hi,
Actually i have seen this program in my book and cant get one thing, the while loop, Why we have used condition not equal to carriage return. One more thing this program is not incrementing the wordcount. it is always showing wordcount=1 no matter how many words the user input.
Please help!
[CODE=c]{
int chcount, wordcount;
char ch;
chcount=0;
wordcount=0;
printf("\nEnter a phrase\n");
while((ch=getch e()!='\r')
{
chcount=chcount +1;
if(ch==' ')
wordcount++;
}
printf("\nChara cter count=%d",chcou nt);
printf("\nwordc ount=%d",wordco unt+1);
}
[/CODE]
Actually i have seen this program in my book and cant get one thing, the while loop, Why we have used condition not equal to carriage return. One more thing this program is not incrementing the wordcount. it is always showing wordcount=1 no matter how many words the user input.
Please help!
[CODE=c]{
int chcount, wordcount;
char ch;
chcount=0;
wordcount=0;
printf("\nEnter a phrase\n");
while((ch=getch e()!='\r')
{
chcount=chcount +1;
if(ch==' ')
wordcount++;
}
printf("\nChara cter count=%d",chcou nt);
printf("\nwordc ount=%d",wordco unt+1);
}
[/CODE]
Comment