Home Segments Index Top Previous Next

504: Mainline

Happily, the read function, scanf, recognizes a %s read specification. On seeing %s, scanf reads a string from the input stream, up to the first whitespace character—space, tab, or carriage return. Then, scanf deposits that string into the memory chunk identified, as always, by an address.

Suppose, for example, that the expression scanf ("%s", input_buffer) is evaluated, given that the next unread characters are C-IBM. The evaluation causes the first part of the input_buffer array to look like this:

    input_buffer 
    *--------*--------* 
    |00000011|10011000| 
    *--------*--------* 
     ----------------- 
             | 
             |  C        -        I        B        M        \0
             |  |        |        |        |        |         | 
             v  v        v        v        v        v         v 
             -------- -------- -------- -------- -------- --------  
        ----*--------*--------*--------*--------*--------*--------*- 
            |01000011|00101101|01001001|01000010|01001101|00000000| 
         ---*--------*--------*--------*--------*--------*--------*--- 
             920      921      922      923      924      925