Classwork 14: String Introduction

Thursday, August 10, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Create the file cw14.c for a classwork assignment and start your file as normal.
  2. Start your assignment with the given example code
  3. Modify the program so that it will accept an input string and search character from the user
  4. An example of running this program:

    linux3[26]% ./cw14
    Input string to search: test_string
    Input character to find: r
    Found character at index: 7
    

  5. Get that version of the program working first
  6. Then modify the program further so that it will replace the found character with a new character specified by the user
  7. Make sure you handle the situation where the character to replace does not occur in the string at all
  8. This new verison of the program should print out the modified string at the end of the program
  9. An example of running this program:

    linux3[27]% ./cw14
    Input string to search: test_string
    Input character to find: r
    Input character to replace with: X
    Replaced string: test_stXing
    

  10. Get this version of the program working
  11. Lastly, modify the program so that it will replace all occurances of the specified character with the replacement character
  12. An example of running this program:

    linux3[27]% ./cw14
    Input string to search: test_string
    Input character to find: t
    Input character to replace with: X
    Replaced string: XesX_sXring
    

  13. Once you are sure the program is done and working well, start a script using script
  14. Once the script is running, show you running the program three, using different strings and replacement characters each time, once where the character to replace does not occur in the string at all.
  15. Exit from the script, which will save the log typescript
  16. Once you are done, use submit to submit two files, cw14.c and typescript

    linux3[26]% submit cs104 cw14 cw14.c typescript
    

  17. After submitting your files, you can verify your files were submitted by using the submitls command
  18. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!