Problem Set: Arrays of Strings in C


  1. Write a function with two parms, an array of strings (each string has 51 locations) and the number of strings. Your function should print the strings on the screen.
  2. Write a function with two parms, an array of strings (each string has 51 locations) and the number of strings. Your function should find the smallest string in the array and return the subscript of the smallest. Use strcmp.
  3. Write a function with two parms, an array of strings (each string has 51 locations) and the number of strings. Your function should remove the newline (if present) from the end of each string. The newline (if present) will be right before the null byte. To remove it, replace it with another null byte.
  4. Write a function with one parm, a string. Your function should change all letters in the string to upper case (those that are not already upper case). Subtract the ASCII values, don't use if anested if, a switch, or the toupper library function. HINT: a char actually contains a number, the ASCII code for the char. Look at the ASCII chart to see the difference between the code for a lower case letter and the matching upper case letter.
  5. Write a function to read into an array of strings from a file. The function should read one line of the file into each string. The parms are the FILE pointer (type FILE *, opened for input), the array of strings (51 locations in each string), and the number of strings. You can assume that the file contains enough lines to fill your array.
  6. Write a main function to do the following:
    1. Create a string that can hold up to 30 characters.
    2. Create an array of 10 strings with room for 50 characters plus the null byte.
    3. Prompt the user and read the name of an input file into your string.
    4. Open the file for input.
    5. Call your function to read from the file into the array. Read into all 10 strings.
    6. Call your function to print all of the strings.
    7. Call your function to remove the newlines at the end of all of the strings.
    8. Call your function to print all of the strings.
    9. Print the smallest string.
    10. Change all of the strings to uppercase.
    11. Print all of the strings again.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2021