Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Alternate post is a link to another way of doing the program which results in same output but with a different programming approach.
:
Run Output
Input a small sentence:Champions are down to earth
Champions
char str[80]; cout<<“Input a small sentence:” ; cin.getline(str,80);
User given sentence is collected in str.
for(int i=0;str[i]!=’ ‘;i++) cout<<str[i];
The loop runs from first index position to the place where first space in the sentence occurs. In each iteration it keeps printing the character it keeps finding, so finally we are able to see the word on screen as the loop finishes.
Notes
In this code we are not separating the word to a different string. We can do so easily by using the another char array and copying character by character to the second array.