Previous: 8.3 Direct I/O with Files
Up: 8 Functions and Files
Next: 8.5 Summary
Previous Page: 8.3.2 Formatted I/O
Next Page: 8.5 Summary

8.4 Common Errors

  1. Use of scanf() to read strings with white space. When scanf() is used to read a string, only part of an input string may be read: it skips over leading white space, and reads a string until the next white space.
    scanf("%s", msg);
    

    Input: this is a string

    With the above input, scanf() will read "this", and NOT the whole string, into memory pointed to by msg. However, printf() will print the entire string until the terminating NULL.

tep@wiliki.eng.hawaii.edu
Wed Aug 17 09:15:23 HST 1994