I have an exercise to write a program that receives a sentence and then takes from each word the first letter and creates a new word.
My code:
int main(){
char* str = new char[50];
for (int i = 0; i < 50; i++)
str[i] = NULL;
cin >> str;
cout<<str;
for (int i = 0; i < 50; i++)
cout << str[i];
system("pause");
return 0;
}
But when I want to print the sentence it prints only the first word.
input:
abcdef abc des
output:
abcdef abc des
abcdef *******************************************
And when I press a space what goes into the array? How can I know when I'm running on the array with the FOR loop When do I get to the Character where there is space?