Hey all. Im currently studying C++ and im having a little bit of trouble figuring out how to count spaces in a string. The program is to enter a full name with any amount of names and print the initials of the first name and print the last name. Im using Borland C++. I have a basic Pseudocode written out for it, here it is:
loop through input and count spaces1
copy first character to output
loop through name again
count spaces
if current character is space
add one to spaces2
increment loop counter
concat next character
concat ". "
when last space is reached
concat until end of input
end loop
print name 2
Im fairly fresh to C++ so im just struggling to figure to code out for this. Here is what I have so far, please dont shoot me down if it is way off :)
char input[ 45 ];
char output[ 45 ];
int spaces;
cout << "Enter Your Full Name: ";
cin.getline( input, 45 );
spaces = 0;
do
{ if (( input [ 45 ] == ' ' ))
spaces++;
}while ( strlen( input ) != 0 );
strcpy( output[ 45 ], input[ 0 ] );