Using your code from the previous question, write a program that reads a multi-line message up to the first full stop and then modifies the contents of the message, so that all whitespace characters are removed. Finally,it should print out the modified message using a single printf statement.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
MUST BE WRITTEN IN C:
FORMAT SHOWN IN IMAGE CANNOT BE EDITED IN ANY WAY
Using your code from the previous question, write a program that reads a multi-line message up to the first full stop and then modifies the contents of the message, so that all whitespace characters are removed. Finally,it should print out the modified message using a single printf statement.
If the user types:
A simple sentence.
the program should output
Asimplesentence.
For the purposes of this question, a whitespace character is either a space, a tab or a newline. Note in particular that the sentence might be spread over several lines.
Input | Result |
---|---|
A simple sentence. | Asimplesentence. |
A sentence with a newline. | Asentencewithanewline. |
![1 #include <stdio.h>|
2 #include <stdbool.h>
3 #define MAX_MSG_LEN 256
4
5 int main(void)
6 - {
int i = 0;
char msg[MAX_MSG_LEN+1];
/* insert appropriate variable declarations */
7
8
9.
10
11
/* read the message from the concole up to first full stop */
12
13
/* loop through the message and keep only non-whitespace characters */
i = 0;
while (msg[i]!='\0')
{
/* only keep a character if it is not a whitespace */
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if (/* insert appropriate guard */) {
/* assign character into modified message */
}
i++;
}
/* DO NOT modify print statement */
printf("%s\n", msg);
28
29
30
return 0;
31
32 }
33](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc2775e8c-94c2-43ee-8379-e9f8aff0b154%2F8c1bbfff-72a9-4406-a574-d085ea4c7943%2Fb6mxzc_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)