CISC105 Summer 2007 Lab06

Notes before you begin:

Programs

    In the next few programs, you will write functions that emulate a few of the standard string manipulation functions in string.h. Read very carefully in your book what the inputs and outputs of these functions are, and also experiment with the functions to see how they work. In the following programs, write a function that does exactly what the string function specified does. Do not use any existing string functions, but rather perform the operations on the character arrays manually. When you are confident that the functions work, demonstrate them in main() alongside the original functions.
  1. Write a function called myStrcpy, which emulates strcpy(). Remember that strcpy returns a char *, remember the order of parameters, and be sure to note that the contents of one of the parameters changes after the function is called. Lastly, remember the null terminating character! Demonstrate the function in the following way, assuming that string is declared as a character array of size 30:
    strcpy(string, "Hello World!");
    printf("%s\n", string);
    myStrcpy(string, "Goodbye, World!");
    printf("%s\n", string);
  2. Write a function called myStrcat, which emulates strcat(). Make sure you have a firm understanding of what strcat() does, and demonstrate your function completely.
  3. Write a function called myStrcmp, which emulates strcmp(). Remember, the basic algorithm that strcmp() uses is something like this:
  4. The next program deals with file input/output.
  5. Write a program that reads in 10 integer values from a file, and puts them in an array. The program should then open a new output file, and print to the file something like this:
    Sum of values: <sum goes here>
    Average of values: <average goes here>
    Thoroughly test the first part before attempting the second part. Make sure you use every step we talked about in class--declare, fopen, test for null, read/write, fclose. Also, make sure to cat your input and output files in the script, along with your .c files. Make up your own input file.

Submission

You should have a total of 4 programs, named lab06.1.c to lab06.4.c. Make a single script file (named lab06.txt) where you cat, compile, and run each program in sequence. That is, you should cat, compile and run lab06.1.c, then do the same with lab06.2.c, etc.

Submit all program and script files on MyCourses before 11:55 Sunday night. Give the paper version of your script to your TA next Monday at the beginning of lab. Write your name and the lab number on the front of your paper submission. Also, if something doesn't work properly, please circle it in bright ink and make a note for your TA explaining the problem. You will lose less points for a problem you recognize and can explain (at least a little) than for one you don't seem to notice.