The C Programming language Chapter 4 Input and Output #黑日工作室 ◆非常感谢天肆掠市建学院 周锦姝老师
The C Programming Language Chapter 4 Input and Output #黑日工作室# 非常感谢 天津城市建设学院 周锦姝老师
The C Programming language Chapter 4 Input and Output Chapter 4 Input and Output C has no lo statements √# include< stdio. h> a Standard input and output U Formatted output --- Printf u Formatted input -- Scanf 日 Examples
The C Programming Language Chapter 4 Input and Output ✓C has no I/O statements ✓ #include <stdio.h> Chapter 4 Input and Output ❑ Standard input and output ❑ Formatted output --- Printf ❑ Formatted input --- Scanf ❑ Examples
The C Programming language Chapter 4 Input and Output 44.1 Standard input and output How to put a character on the standard output (normally the display) putchar(c c may be character constants, variables and expressions /*ch41.c* #include <stdio.h> main 运行结果:A char a 65:a=B B putchar(); putchar('in); putchar(a)
The C Programming Language Chapter 4 Input and Output /*ch4_1.c*/ #include <stdio.h> main( ) { int c; char a; c=65; a='B'; putchar(c); putchar('\n'); putchar(a); } 运行结果:A B 4.1 Standard input and output ❖How to put a character on the standard output (normally the display) ➢ putchar( c ) ➢ c may be character constants,variables and expressions
The C Programming language Chapter 4 Input and Output .s How to read one character at a time from the standard input (normally the keyboard getchar () /*ch42.c* #include <stdio h> w, mainO i int c 运行结果 printf("Enter a character Enter a character: A J A--->hex 1 getchar printf("%oc--->hex%n",c, c)
The C Programming Language Chapter 4 Input and Output getchar( ) 例 /*ch4_2.c*/ #include <stdio.h> main() { int c; printf("Enter a character:"); c=getchar(); printf("%c--->hex%x\n",c,c); } 运行结果: Enter a character:A A--->hex41 ❖How to read one character at a time from the standard input (normally the keyboard)
The C Programming language Chapter 4 Input and Output 4.2 Formatted output -- Printf printf (char *format, argl, arg2,..) printf converts, formats, and prints its arguments on the standard output under control of the format printf max=%d, min=%05d\n,a, b) 沙 Notice: The fol例ita ects: printf(%od %dn, a, b) Ordinar printf(a=%d, b=%d\n?", a, b); eam, Convers输出结果:34 and printing of the a=3.b=4 %o modifier conversion character
The C Programming Language Chapter 4 Input and Output ➢ printf (char *format, arg1,arg2, ...) ➢ printf converts ,formats,and prints its arguments on the standard output under control of the format 4.2 Formatted output --- Printf Notice : The format string contains two types of objects: ▪Ordinary characters: copied to the output stream; ▪Conversion specifications: cause conversion and printing of the next successive arguments to printf. % [modifier] conversion character 例 int a=3,b=4; printf(“%d %d\n”,a,b); printf(“a=%d , b=%d\n”,a,b); 输出结果: 3 4 a=3, b=4 printf (“max=%d,min=%5d\n” , a , b);