C Input/Output

I/O Functions

See the list of functions on this reference website.

Standard input/output

We must #include <stdio.h> to use this library. The standard (built-in) streams are defined there:

Output in C

Prerequisite: #include <stdio.h> in header to access library functions; Reference for stdio.h

Input in C

Character-based Input

Formatted Input

Here is a list of the most common conversion specifications:
    %d integer  
    %ld long 
    %c char
    %s string
    %f float (real number type)
    %lf double, Lf long double
There are also many fancy input format options, see scanf documentation for details:

Here is a short example: ```c #include <stdio.h> int main() { int number; float x; double y; char word[20]; scanf("%d", &number); scanf("%f %lf", &x, &y); scanf("%s", word); } ```

Note that we don't need & in front of word because as an array it is an address already. We also don't use a subscript since we're reading into the whole array. When reading a string, scanf only reads up to first whitespace (space, tab, ret). You must make sure memory is allocated for it and big enough to hold the characters that are input!

Sequential Files