0

plz write a prigramme to count no of words in a string

21st Oct 2016, 6:41 AM
ASHISH RAKESH
ASHISH RAKESH - avatar
4 Respostas
+ 1
You can increment a variable whenever a '\b' (space bar ) is encountered
22nd Oct 2016, 2:05 PM
Jishnu
Jishnu - avatar
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; }
21st Oct 2016, 11:24 AM
Jishnu
Jishnu - avatar
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?
21st Oct 2016, 1:51 PM
Andrea Mancini
Andrea Mancini - avatar
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?
26th Oct 2016, 9:27 PM
Boris Ferguson
Boris Ferguson - avatar