G
G
Gimir2017-10-09 14:10:49
C++ / C#
Gimir, 2017-10-09 14:10:49

Is there a command in C that calculates how many words are in a string variable?

Like for example a command strlen();that calculates the number of characters in a string.
I need to count the number of words in a line that the user will enter in the terminal, so that I can then print the beginning of each word.
For example, the user enters: Sasha Kozlov and the program displays SK.
For example, when declaring the main function:
int main (int argc, string argv[]) { }
just like int argc calculates the number of arguments entered by the user when starting the program, I need the number of words entered by the user into the terminal using the getstring().

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2017-10-09
@GavriKos

\0 is always one - it's the line ending character.
But there are no functions for counting any Wishlist, including the number of words. Because the language doesn't need it. You need - you and consider yourself.

D
DVoropaev, 2017-10-09
@DVoropaev

Loop through all characters, and look for letters that come after spaces

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question