Write a program to remove all punctuation marks from an inputted message. The program should read an input message from a user into an array of characters; it should then modify the contents of the message, so that all punctuation marks are removed; and finally it should print out the modified message using a single printf statement. If the user types: Too, many, punctuation marks:; by far!! the program should output Too many punctuation marks by far For the purposes of this question, a punctuation mark is any one of the following seven characters !’?;:,. For example: Input Result Too, many, punctuation marks:; by far!! Too many punctuation marks by far Hyphen "-" survives ; why? as it is not one of the listed punctuation marks. Hyphen "-" survives why as it is not one of the listed punctuation marks
Write a program to remove all punctuation marks from an inputted message. The program should read an input message from a user into an array of characters; it should then modify the contents of the message, so that all punctuation marks are removed; and finally it should print out the modified message using a single printf statement.
If the user types:
Too, many, punctuation marks:; by far!!
the program should output
Too many punctuation marks by far
For the purposes of this question, a punctuation mark is any one of the following seven characters !’?;:,.
For example:
Input | Result |
---|---|
Too, many, punctuation marks:; by far!! | Too many punctuation marks by far |
Hyphen "-" survives ; why? as it is not one of the listed punctuation marks. | Hyphen "-" survives why as it is not one of the listed punctuation marks |
Code I was given:
#include <stdio.h>
#define MAX_MSG_LEN 256
int main(void)
{
char msg[MAX_MSG_LEN+1];
fgets(msg, MAX_MSG_LEN, stdin);
/* write your solution here ... */
return 0;
}
Step by step
Solved in 3 steps with 1 images