Counting spaces in a char array

Jul 8, 2013 at 10:10pm
When I put any sentence say "Hello my name is bob." When using the stdlen in a manner such as
1
2
3
4
cout << "Please insert sentence"; 
cin >> sentence;
nums[0] = strlen(sentence); 
//where sentence is a char array //  

it stops detecting after Hello. The reason being I am guessing after the 'o' there is a /0 signifying a void and thus the means to terminate the scan. So how does one count the character of the entire sentence including the spaces?
Jul 8, 2013 at 10:14pm
std::getline( std::cin, sentence );

provided that sentence has type std::string. Or

std::cin.getline( sentence, sizeof( sentence ) );

provided that sentence is a character array.
Last edited on Jul 8, 2013 at 10:15pm
Jul 8, 2013 at 10:45pm
but how would I get num [0] = sizeof (sentence)? I intend to manipulate this number for other uses. Sorry if I mislead a bit.
Jul 8, 2013 at 10:47pm
The same way as you wrote.:)
Jul 8, 2013 at 11:02pm
I see thanks.
Topic archived. No new replies allowed.