CH - 5 Input-Output
CH - 5 Input-Output
MANAGING INPUT –
OUTPUT OPERATIONS
Prepared by:
Ms. Pankti Dharwa
(SVBIT, CE dept)
INPUT / OUTPUT WITH SCANF() /
PRINTF()
• SYNTAX:- Printf(“Controlstring”,list of
address variables)
• Control string
• Ex:-main()
{
char c;
printf(“enter one character\t”);
c=getchar();
printf(“Input character is );
putchar(c);
}
Output:- Enter one character a
Input character is = a
• getch();
• getche();
• Ex:-main()
{
char c;
printf(“enter one character\t”);
c=getch(); //input not echoed
printf(“\n Input second character );
c1=getche(); //input echod
}
Output:- Enter one character //a
Input second character b
STRING INPUT / OUTPUT
(ch 8)
• Gets() and puts() are used to read a
string & print the string.
• gets(string_variable) puts(string_variable)
Ex:- char name[10]; puts(“hello”);
gets (name);
• scanf(“%d %d”,&a,&b);
• printf(“a= %d b=%d”,a,b);
• i/p = 44 66
• o/p- a=4321 b=44
• printf(“%5d”,123); 1 2 3
• printf(“%2d”,123); 1 2 3
• printf(“%05d”,123); 0 0 1 2 3
• printf(“%-5d”,123); 1 2 3
• printf(“%+5d”,123); + 1 2 3
printf(“%#5o”,123); 0 7 1 0
The format for floating data is %w.pf
• printf(“%f”,45.678); 4 5 . 6 7 8 0 0 0
• printf(“%7.2f”, 45.768); 4 5 . 6 8
• printf(“%-7.2f”,45.768); 4 5 . 6 8
• printf(“%7-.2e”,45.678); 4 . 5 7 e + 0 1
• printf(“%e”,45.678); 4 . 5 6 7 8 0 0 e + 0 1