October 2004
Beginner
408 pages
9h 24m
English
Once you've opened a file for writing (meaning that you used either the w or a mode, or a variant thereof), you can write data to it. To do so, you can use the fprintf() function, which works like printf() except that it takes a file pointer as its first argument:
fprintf (file_pointer, formatting, extra_arguments);
The formatting signifiers are exactly the same as those used with printf() and scanf() (Table 12.2). So, to write an unsigned integer to a file, you would code
fprintf (fp, "%u", 30);
| fprintf() Signifiers | |
|---|---|
| Signifier | Meaning |
| d | integer |
| f | floating point number |
| hd | short integer |
| ld | long integer |
| hu | unsigned short integer |
| u | unsigned integer |
| lu | unsigned ... |
Read now
Unlock full access