SI 204 Spring 2017 / HWs


This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Homework 12: fscanf

Name: _____________________________________________ Alpha: ___________________

Describe help received: ________________________________________________________

  • Due before class on Wednesday, February 8
  • This homework contains code to be submitted electronically. Put your code in a folder called hw12 and submit using the 204sub command.
  • This is an electronic homework and you do not need to print out anything to turn in during class.

Assignment

  1. Required reading: Sections 3 (Pointers) and 4 (fscanf) from the Unit 4 notes,
  2. Write a program called age.c that reads a name and a birthday such as "Philip 1/31/1937" and prints out a line with their age as of February 6, 2017, for example "Philip is 80 years old."
    roche@ubuntu$ ./age
    Philip 1/31/1937
    Philip is 80 years old.
    
    roche@ubuntu$ ./age
    Steve 10/3/1936
    Steve is 80 years old.

    You must use a fscanf statement to read in the input line! Note that someone born on February 6 would be considered to have their birthday already, so someone born on 2/7/2016 would be 0 years old while someone born on 2/6/2016 would be 1 years old.