Basic Input and Output

710 views
558 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
710
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
33
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Basic Input and Output

  1. 1. SCANF &PRINTFInput Statement -> SCANF scanf() is used to give data to variables using keyboard scanf works very well when the viewer’s input has NO spacesOutput Statement ->PRINTF printf() is used to show the result of the program trough display device
  2. 2. GETS &PUTSInput Statement -> GETS gets() function accepts an entire line of input from the standard input device (keyboard)Output Statement ->PUTS It is complement of gets. Its display a string on the standard output device
  3. 3. REVISE LAB 3Exercise 1a. #include<stdio.h> #include<conio.h> main() { Enter subject name: Computer Programming char subject[20]; Your name is: Computer printf("Enter subject name:"); scanf("%s", &subject); printf("Your name is: %s n",subject); getch(); }b. #include<stdio.h> #include<conio.h> main() { Enter subject name: Computer Programming char subject[20]; Your name is: printf("Enter a subject name:"); Computer Programming gets(subject); printf("Your name is: n"); puts(subject); getch(); }
  4. 4. Cannot read a multi-word string such as computer programming Its read only computer scanf terminates it input when it encounter a blank space such as space, tab, new line, form feed, carriage return. Overcomes the disadvantages of scanf functionsIt can read any string length with any numbers of blank space
  5. 5. GETCHAR &PUTCHAR • Define in the standard C header stdio.hInput Statement -> GETCHAR • getch is used to read a character with pressing the enterOutput Statement ->PUTCHAR • Complement of the getchar function • To display a single character on the standard output device
  6. 6. GETCH &PUTCH • Accessed from <stdio.h> standard libraryInput Statement -> GETCH • getch is used to returns a single character typed in from the standard input deviceOutput Statement ->PUTCH • As soon as key is pressed it stop accessing the keyboard. • User don’t have to press the ENTER key.
  7. 7. REVISE LAB 3Exercise 1c. #include<stdio.h> #include<conio.h> main() { Enter a character: Computer Programming char letter; Your Input is: printf("Enter a character:"); C letter=getchar(); printf("nYour input is: n"); putchar(letter); getch(); }d. #include<stdio.h> #include<conio.h> main() { Enter subject name: char letter; Your name is: printf("Enter a character:"); C letter=getch(); printf("nYour input is: n"); putch(letter); getch(); }
  8. 8. What is a STRING?? a string is a character variable with more than one character. Strings can be abbreviations, words, phrases, sentences, or even paragraphs
  9. 9. Can be said as : Format specifier Format string
  10. 10. Format Output Type OutputSpecifier Example %d Signed decimal integer 76 %i Signed decimal integer 76 %o Unsigned octal integer 134 %u Unsigned decimal integer 76 %x Unsigned hexadecimal (small letter) 9c %X Unsigned hexadecimal (capital letter) 9C %f Integer including decimal point 76.0000 %e Signed floating point (using e notation) 7.6000e+01 %E Signed floating point (using E notation) 7.6000E+01 %g The shorter between %f and %e 76 %G The shorter between %f and %E 76 %c Character ‘7’ %s String ‘76
  11. 11. Why Use Format Specifier?? Nature of c requires that I/0 operations be associated with specifier data types. This association is made with format and conversion specifiers. When use with the input statements, conversion specifiers tell what kind of variable is being read
  12. 12. Example scanf(“%lf”,& x); Tells C to interpret character type at the keyboard as real number of type double
  13. 13. Also said as sscape sequencesIts allow you to send nongraphic control characters to a displaydevice Basic Constant Effect a Beep sound b Backspace f Formfeed (for printing) n New line r Carriage return t Tab v Vertical tab Backslash ” “ sign o Octal decimal x Hexadecimal O NULL

×