JMU
Input/Output in C
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Getting Started
Files and the Console
Opening/Closing Files
ASCII I/O
The Format String
Some Flags
- Left justify
0 Pad with 0s instead of blanks
+ Prepend the sign
Some Conversion Specifiers
d, i Signed integer
f Floating point
u Unsigned integer
s String (i.e., pointer to an array of char)
c Character
o Unsiged octal
x Unsigned hexadecimal
e Floating point in scientific notation
p Pointer (as a character sequence)
n Write the number of characters written so far to the given address
The Format String (cont.)

An Example

    int    n;

    printf("The answer is %d!", n);
  
ASCII I/O with a File
Creating Formatted Strings
Binary Input/Output