Practice: C File I/O


  1. Download "people.dat" from Files->C FileIO.
  2. Create a main function that does the following:
    1. Create strings for name (41 chars), nickname (21 chars), profession (41 chars), and age (int).
    2. Open "people.dat" for input and "people.out" for output.
    3. For each person in the file:
      1. Read name, nickname, profession, and age for each person. Each string is on a separate line and may contain multiple words.
      2. For each string call your function to remove the newline.
      3. Call your function to print the person.
  3. Write a function to check whether a string has a newline right before the nullbyte. If there is a newline, replace it with a nullbyte.
  4. Write a function with two string parms. Your function will set the second string to the uppercase of the first string. Call the C library function char toupper(char) which converts a character to uppercase. Include for the prototype of toupper.
  5. Write a function to print a person. The parms are the output FILE pointer, and the fields for a person. Call your upper function to change the nickname to uppercase, and then print the person to the output file in the following format:
  6.      Shaquille O'Neill (SHAQ)
         profession: basketball player
         age: 49


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

© Copyright Emmi Schatz 2021