November 10th, 2013, 04:32 PM
Hello everyone. I am having a problem with a small program I am trying to create. Main function of the program is to receive a String and print how many words it contains. For example if I give as input "Hello World" It should return 2. Althought the user can leave more than one space between the words. The problem is that it always returns me 3 as a result.
Here's the code.
printf("Give me a string \n");
printf("Sum equals to %d", sum);
November 10th, 2013, 07:49 PM
Do you realize that scanf() stops processing your string when it encounters a whitespace character? Also using scanf() to retrieve a string, without using the proper width specifier is very dangerous.
November 11th, 2013, 02:09 PM
Thank you for the quick reply Jim. Do you have any suggestions how can I complete the task since scanf is out of the question.
Originally Posted by jimblumberg
November 11th, 2013, 02:13 PM
[/code] are essential for python code and Makefiles!