CISC105 - General Computer Science
Homework #3
Structures, Character Strings and I/O
1. (6) Given the following code, set the year for today's date to 1991.
struct date
{
int month;
int day;
int year;
};
struct date todays_date;
2. (6) Write the code to call a function named 'number_of_days' passing today's date
from Problem #1 above as an argument.
3. (6) Initialize a date structure (that has the format given in Problem #1) called
'tomorrows_date' with the date July 4th, 1776.
4. (10) Using the date structure from Problem #1, declare a date structure with twelve
birthdays and set the month of the fifth entry to twelve.
5. (10) Code a structure called 'date_time' containing a date structure and a time
structure as its members.
6. (10) Code a structure called 'employee' containing a social security number and a
twenty character name as its members.
7. (6) Given the following code and using the code from Problem #6, set the first
character of the name to R.
struct employee payroll_rec;
8. (6) Rewrite the following code using a character string:
static char word [] = {'H','e','l','l','o','!','\0'};
9. (6) Code a statement to display the following:
Single quotes (') and backslash (\) are special.
10. (6) Given the following information, convert the character '5' to the number 5
using integer arithmetic. (ASCII values for the characters '0' through '9'
are 48 through 57 respectively).
int i;
char c = '5';
11. (10) Write the code needed to read from a file.
12. (18) Match the function with its purpose.
_____fprintf A. Writes to a file instead of a terminal.
_____fscanf B. Reads from a file instead of a terminal.
_____fopen C. Initializes a file for I/O operations.
_____fclose D. Tells the system that a file is no longer
needed to be accessed.
_____feof E. Tests for an end of file condition.
_____fgets F. Reads entire lines of data from a file.
_____fputs G. Writes entire lines of data to a file.
_____fgetc H. Reads a single character from a file.
_____fputc I. Writes a single character to a file.
J. Reads a single character from a terminal.
K. Writes a single character to a terminal.