Classwork 27: Blue Censor
Practice working with string functions from various libraries.
Write a program that takes a line of text entered by the user and replaces every occurrence of the substring "blue" with the characters "@!#$". A sample run of your program might look like:
PT% ./a.out Enter a string: I tied a blue balloon to the blue smurf and he floated up to the blue sky. Censored text: "I tied a @!#$ balloon to the @!#$ smurf and he floated up to the @!#$ sky." PT%
Use functions from the string library to make this program simple.
- You should use the readline() function to read
the user's input. Don't forget to add to the top of your program:
- Don't forget to free the string returned by readline() when you don't need the string anymore.
- When you use readline(), you must tell
gcc to use the readline library:
gcc -Wall censor.c -lreadline
- You might find the strstr() function in the string library particularly useful. Here's an example of how to use strstr(): strstr.c.
SubmitUse the script command to record several sample runs of your program. Then, submit your program and sample run as usual:
submit cs104_chang cw27 censor.c submit cs104_chang cw27 typescript