0
PRINTF(), SCANF()
CONVERSION SPECIFIERS
ESCAPE SEQUENCES
Input Output Management
Compiled By: Kamal Acharya
INPUT and OUTPUT
Compiled By: Kamal Acharya
 printf() will print formatted output to the screen.
 To print a message:
printf("This is a messagen");
 How do we prin...
Compiled By: Kamal Acharya
int degreesF = 68;
printf("The temperature is %d degrees.", degreesF);
Specifier for
“print an integer value”
“and the val...
int a = 1;
int b = 2;
int c = 3;
printf(“%d plus %d is equal to %d", a, b, c);
1 plus 2 is equal to 3
Output:
Compiled By:...
 Format specifiers:
 %c for single characters
 %d for integers
 %f for float/double (fractions): 1234.56
 %g for floa...
Output:
A 65 41 101
Example:
char a='A';
printf("%c %d %x %0", a, a, a, a);
Compiled By: Kamal Acharya
Format specifier can be used with modifiers
Example :
%-6d, %5d, %6.2f
Modifier
digit
Description
Allocate minimum width (...
Statement Output
printf("|%d|", 987); |987|
printf("|%2d|", 987); |987|
printf("|%8d|", 987); | 987|
printf("|%-8d|", 987)...
printf(“Hello n World!");
Hello
World!
Output:
‘n’ is not a data to be printed. Instead, it is a command that tells the
mo...
Control Characters (Escape Sequences)
Character
'n'
't'
'v'
'r'
'x41'
'101'
'0'
'''
'"'
''
'b'
'f'
'a'
Description
newline...
Figure: Output specification for inventory report
printf (“Part NumbertQty On HandtQty On OrderttPricen”);
t t tt n
Compil...
Keyboard input: scanf()
 scanf() will scan formatted input from the keyboard.
 It uses the same format specifiers as pri...
Compiled By: Kamal Acharya
Format specifiers for scanf()
 Format specifiers:
 %c for single characters
 scanf(" %c", &some_character);
 %d for in...
Escape Sequences
Compiled By: Kamal Acharya
Upcoming SlideShare
Loading in...5
×

Input Output Management In C Programming

560

Published on

This slide provides the introduction to the input and output process available in C Programming.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
560
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
31
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Input Output Management In C Programming"

  1. 1. PRINTF(), SCANF() CONVERSION SPECIFIERS ESCAPE SEQUENCES Input Output Management Compiled By: Kamal Acharya
  2. 2. INPUT and OUTPUT Compiled By: Kamal Acharya
  3. 3.  printf() will print formatted output to the screen.  To print a message: printf("This is a messagen");  How do we print the value of a variable?  Answer: Use special format specifiers depending on the type of the variable this is a string literal Printing Output: printf() Compiled By: Kamal Acharya
  4. 4. Compiled By: Kamal Acharya
  5. 5. int degreesF = 68; printf("The temperature is %d degrees.", degreesF); Specifier for “print an integer value” “and the value of that number is read from this variable” > The temperature is 68 degrees. Output: Compiled By: Kamal Acharya
  6. 6. int a = 1; int b = 2; int c = 3; printf(“%d plus %d is equal to %d", a, b, c); 1 plus 2 is equal to 3 Output: Compiled By: Kamal Acharya
  7. 7.  Format specifiers:  %c for single characters  %d for integers  %f for float/double (fractions): 1234.56  %g for float/double (scientific): 1.23456E+3  %s for phrases or ‘strings’ Compiled By: Kamal Acharya
  8. 8. Output: A 65 41 101 Example: char a='A'; printf("%c %d %x %0", a, a, a, a); Compiled By: Kamal Acharya
  9. 9. Format specifier can be used with modifiers Example : %-6d, %5d, %6.2f Modifier digit Description Allocate minimum width (in characters). .digit Number of floating-points - left justified l Print the data as a long integer. Compiled By: Kamal Acharya
  10. 10. Statement Output printf("|%d|", 987); |987| printf("|%2d|", 987); |987| printf("|%8d|", 987); | 987| printf("|%-8d|", 987); |987 | printf("|%0.2f|", 9876.54); |9876.54| printf("|%4.2f|", 9876.54); |9876.54| printf("|%3.1f|", 9876.54); |9876.5| printf("|%10.3f|", 9876.54); | 9876.540| Compiled By: Kamal Acharya
  11. 11. printf(“Hello n World!"); Hello World! Output: ‘n’ is not a data to be printed. Instead, it is a command that tells the monitor to move the cursor to the next line Compiled By: Kamal Acharya
  12. 12. Control Characters (Escape Sequences) Character 'n' 't' 'v' 'r' 'x41' '101' '0' ''' '"' '' 'b' 'f' 'a' Description newline horizontal tab vertical tab carriage return hexadecimal number, 0x41 octal number 101 null character - indicates the end of a string single quatation mark (') double quatation mark (") backslash mark () backspace formfeed - next page (used for printer) alert - produce a beep sound Compiled By: Kamal Acharya
  13. 13. Figure: Output specification for inventory report printf (“Part NumbertQty On HandtQty On OrderttPricen”); t t tt n Compiled By: Kamal Acharya
  14. 14. Keyboard input: scanf()  scanf() will scan formatted input from the keyboard.  It uses the same format specifiers as printf()  To read an integer:  int num_students; scanf("%d", &num_students); Specifier for “reading an integer value” VERY IMPORTANT special symbol “Place value into this variable” Compiled By: Kamal Acharya
  15. 15. Compiled By: Kamal Acharya
  16. 16. Format specifiers for scanf()  Format specifiers:  %c for single characters  scanf(" %c", &some_character);  %d for integers  scanf ("%d", &some_integer);  %f for float  scanf ("%f", &some_float);  %lf for double  scanf ("%lf", &some_double); always put a space between " and % when reading characters Compiled By: Kamal Acharya
  17. 17. Escape Sequences Compiled By: Kamal Acharya
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×