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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 8PP: (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays...
icon
Related questions
icon
Concept explainers
Question

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning