CS 211 - Lab 5

Fall 2012

Due: Monday, October 1st, 2012 at 11:59 pm

Find and Replace

For this lab, you are to write a C program that will perform a "find and replace" of characters in a string.

Input will be given in the following manner:

#target#replacement#

originalString1

originalString2

...

When the first character on the line is the # symbol, you have a new target-replacement pair. For the original strings that follow, you are to find all occurences of the target substring in the original string and replace the target with the replacement substring. Note that the lengths of the target and the replacement do not need to match. The target substring must be of length of 1 or greater, but the replacement substring can be of zero length. If a zero length target is given, print an error message, ignore the current line and continue processing the input.

Your program is to process each "original string" line using the last valid target-replacement pair. If the input does not begin with a target-replacement pair, your program should do zero substitutions until a valid target-replacement pair is given.

The input is to come from a file. This file may be given as a command line argument. If no command line argument is given, your program is to prompt the user for the name of the input file.

An example input file can be found at: lab5.txt

The output of the program is to be given to standard output. When a new target-replacement pair is read in by your program, you are to print out some message showing the new values of both the target and replacement substrings. When an "original string" is read in by your program, your program is to output (in this order!) the original string, the total number of substitutions made and the final string. This information is to be formatted in some readable manner.

For purposes of this program you may assume that each string from the file is at most 100 characters long. Also, you may assume that each final string is at most 300 characters long.

The strncmp () library function may be useful for this program depending on your approach.

Program Submission

Your are to submit the programs for this lab via the Assignments Page in Blackboard.

To help the TA, name your file with your net-id and the assignment name, like:

  • ptroy1LabX.c

Submit this file via the Assignment Link for the Lab in Blackboard.

  1. In the CS 211 Web Pages in Blackboard, go to the Assignments Page
  2. Click on the link for the correct lab. This will open a web page with the title: "Upload Assignment: Lab X", where X is the number of the lab
  3. Scroll down and click on the button "Browse for Local File"
  4. Select the file that you created that contains the program. Then click OK.
  5. Repeat steps 3 and 4 for your second program.
  6. Click the submit button on the "Upload Assignment: Lab X" page.
  7. You should see the Submission History page that shows what you submitted. Verify you actually submitted the correct information.
-- Main.troy - 2012-09-26
Topic attachments
I Attachment Action Size Date Who Comment
Texttxt lab5.txt manage 0.2 K 2012-09-26 - 13:36 UnknownUser  
Topic revision: r2 - 2012-09-26 - 18:41:38 - Main.ssiddi38
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF