O'Reilly logo

Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 24. Input, Output, Files

You’ve been using printf to print things, and that’s great and all, but you need more. In this exercise, you’ll be using the functions fscanf and fgets to build information about a person in a structure. After this simple introduction about reading input, you’ll get a full list of the functions that C has for I/O. Some of these you’ve already seen and used, so this will be another memorization exercise.

ex24.c

  1   #include <stdio.h>   2   #include "dbg.h"   3   4   #define MAX_DATA 100   5   6   typedef enum EyeColor {   7       BLUE_EYES, GREEN_EYES, BROWN_EYES,   8       BLACK_EYES, OTHER_EYES   9   } EyeColor;  10  11   const char *EYE_COLOR_NAMES[] = {  12       "Blue",

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required