Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a code that allows the user to enter a phrase of multiple words into a str

ID: 3552915 • Letter: W

Question

Write a code that allows the user to enter a phrase of multiple words into a string. Start by declaring a string of 101 characters called 'mystr'. If you use the statement below to read a phrase from the user into the string, only the first word will be captured. For example, if the user enters "Good morning", only the word "Good" will be saved in the string since the 'scanf stops reading after the space character. scanf("%100s', mystr); To read a phrase into the string, write a loop that iterates 100 times and reads a character in each iteration. The character is saved in the string. When the user hits the 'enter' key, the loop should terminate. The 'enter' key is ASCII number 10. At this ASCII, you can use the 'break' statement to terminate the loop. After the loop finishes, make sure you put a NULL character (ASCII code = 0) at the end of the string so it can be printed correctly. Below is a sample output. Enter a multi - word string: How are you doing? The string is: How are you doing?

Explanation / Answer

#include<stdio.h>

int main()

{

char s[101];

printf("Enter a multi-word string ");

for(int i=0;i<100;i++)

{

scanf("%c",&s[i]);

if(s[i]==10)

{

s[i]= 0;

break;

}

}

for(int i=0;s[i]!=0;i++)

{

printf("%c",s[i]);

}

int n;

scanf("%d",&n);

}

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote