Sunday, August 2, 2009

Need a short c++ program that counts how many words in a string?

cin%26gt;%26gt;"this is a test"


cout%26lt;%26lt; x %26lt;%26lt; "words in your string";





where x is determined to be 4 by some short function.

Need a short c++ program that counts how many words in a string?
the simplest one would be to count the no. of spaces in the string and report %26lt;%26lt;no_of_spaces+1 .


that's ofcourse the most basic program.. and it'll give u wong results more often than not.





ican post u the exact code.. (the perfect program) for this.. if u really need.. but it'll ofcourse take some time
Reply:Oh come on -- this is too easy to ask for help with. How far are you going to get asking someone else to do your homework for you?





Look, this is the basic pseudocode:





x = 0


while not (end of string) do {


if (current character is a blank space){


if (next character is not a blank){


x = x + 1


}


}


}


return x





that's basically it.


No comments:

Post a Comment