Previous: 12.6 Summary
Up: 12 Structures and Unions
Next: 12.8 Problems
Previous Page: 12.6 Summary
Next Page: 12.8 Problems

12.7 Exercises

  1. Find and correct errors if any. What will be the output?

    struct node {
         int id;
         int score;
    }
    

    #include <stdio.h> main() { struct node *px, x, y; px = &x; while (scanf("%d %d", px.id, px.score) != EOF) printf("%d %d\n", *px.id, *px.score); }

  2. Define a data structure, intflt, that will allow one to store either an integer or a float. Read strings and convert them to either integers or floats depending on whether there is a fractional part present. Store the resulting values in an intflt type array. When the input is terminated, print the stored values.

tep@wiliki.eng.hawaii.edu
Sat Sep 3 07:12:43 HST 1994