Sams Teach Yourself C in 21 Days

(singke) #1
Answers 871

F


Answers for Day 19

Quiz


  1. Type double.

  2. On most compilers, it’s equivalent to a long; however, this isn’t guaranteed. Check
    the TIME.H file with your compiler or your reference manual to find out what
    variable type your compiler uses.

  3. The time()function returns the number of seconds that have elapsed since mid-
    night, January 1, 1970. The clock()function returns the number of 1/100 seconds
    that have elapsed since the program began execution.

  4. Nothing. It simply displays a message that describes the error.

  5. Sort the array into ascending order.

  6. 14

  7. 4

  8. 21

  9. 0 if the values are equal,>0if the value of element 1 is greater than element 2, and
    <0if the value of element 1 is less than element 2.
    10.NULL


Exercises


  1. The code is as follows:
    bsearch( myname, names, (sizeof(names)/sizeof(names[0])),
    sizeof(names[0]), comp_names);

  2. There are three problems. First, the field width isn’t provided in the call to
    qsort(). Second, the parentheses shouldn’t be added to the end of the function
    name in the call to qsort(). Third, the program is missing its comparison function.
    qsort()usescompare_function(), which isn’t defined in the program.

  3. The compare function returns the wrong values. It should return a positive number
    ifelement1is greater than element2and a negative number if element1is less
    thanelement2.


49 448201x-APP F 8/13/02 11:22 AM Page 871

Free download pdf