Homework 11: Strings Homework

Wednesday, April 18, 2012     


[Up] [Previous Homework] [Next Homework]


Complete the following:

Solution

  1. NOTE: You need to start indenting your programs properly. Points will be taken off for not indenting this homework appropriately
  2. Reminder to look at CMSC104 Indentation Standards
  3. Create a new h11.c file
  4. You are going to implement a program to censor bad words
  5. Or, more generally, you are going to implement a program to search for a string inside another string and replace it
  6. Your program should take two strings (give a maximum size of 50 characters) as input from the user
  7. Your program should then search the first string to see if the second string occurs in it
  8. For every instance of the second string found inside the first string, all the characters that matched the second string should be replaced with X'es
  9. Your program should then print out the censored first string
  10. Example run:

    linux2[1]% ./hw11
    Input string: hey_this_is_a_test
    Input string to censor: is
    Censored string: hey_thXX_XX_a_test
    linux2[1]% ./hw11
    Input string: more_test_to_show_testing_my_code
    Input string to censor: test
    Censored string: more_XXXX_to_show_XXXXing_my_code
    linux2[1]% ./hw11
    Input string: more_test_to_show_testing_my_code
    Input string to censor: blah
    Censored string: more_test_to_show_testing_my_code
    

  11. Create a script of you running your program three times.
  12. Once you are done, use submit to submit two files, hw11.c and typescript

    linux3[1]% submit cs104_sheets hw11 hw11.c typescript