0
plz write a prigramme to count no of words in a string
4 Respostas
+ 1
You can increment a variable whenever a '\b' (space bar ) is encountered
0
Void main ()
{
Int x,y;
Char st[50];
Cout<<"enter a string";
gets(st);
For(int i=1;st[i]!='\0';++i){
Switch(i)
{
case a:;
Case e:;
Case I:;
Case o:;
Case u:++x;break();
Default :++y;
}
Cout<<"total string"<<x+y;
Cout<<"total vovels"<<x;
Cout<<"total consonants"<<y;
}
0
Reading this it seems that counts only letters, not the words... An idea could be increment a variable every time the i variable is equal to the ascii value for the space (including exeptions for a double tap of space), what do you think?
0
Why not count the number of spaces in the string before you reach the end of the string? (It would be wise to check whether or not the first or last character was a space too as it would alter your total amount of words calculated)
Does that help?