Chapter 3: I/O Management
printf() and scanf() function printf() and scanf() function are used as basic I/O function. printf syntax: printf(string, expression1, expression2, ……) No limit on number of value can be that can be printed Format string may contain ordinary character and conversion specification begin with % Conversion specifier specifies compiler to convert into specific format. Though compiler doesn’t check the conversion specification number should match.
Why following printf() is wrong printf(“%d %d”, i); printf(“ %d”, i, j); int i; float x; printf(“%f %d\n”,i,x);
Conversion Specifier d deimal e floating point is exponential f Display floating point number c character s string %.1f display float value with one digit decimal %4d display with space in front (Right justification) %-4d display with space in back (Left Justification)
Example
Escape Sequence Non printing character having special meaning Start with \ Some common escape sequence are
The scanf() function Takes input from user, Syntax scanf(“string ”, &variable, &variable, ………..) Never FORGET to use & before variable Confusing printf() and scanf() …
Input fraction
Thank you