Standard input and OUTPUT functions
#include <stdio.h>
Stdio is an abbreviation for standard input & output
Character data input/output function: Putchar (), GetChar ()
Format input and OUTPUT functions: printf (), scanf ()
1. Character output function: Putchar (), output one character to the monitor
1#include <stdio.h>2 intMain () {3 CharA, B;4A ='H';5b ='I';6 7 Putchar (a); 8 Putchar (b);9Putchar ('\ n');TenPutchar ( the); One Putchar (b); A}
2. Character input function: GetChar (), get a character from device (keyboard)
1 #include <stdio.h>2int main () {3 char C; 4 c = GetChar (); 5 Putchar (c); 6 Putchar ('\ n') ; 7 }
3. Formatted output function, printf (), can be interpreted as print function abbreviation (printing functions)
1 //%d decimal integral type2 //%o Eight-input integer3 //%x hexadecimal integral type4 //%u unsigned form output integral type5 //%c one character6 //%s A string7 //%f A floating-point number (single-and double-precision)8 //%e Scientific Counting method output floating-point number9 //%g output%f%e occupies a shorter number of bitsTen One //%ld Long Integer type A //-Left alignment default right alignment - //dd%5d length is greater than or equal to 5, as-is output, less than 5 bits, the left space is padded,%-5d right space - //dd.dd the#include <stdio.h> - intMain () { - Charc ='a'; - inti =1234; + floatf =12.123456; - DoubleD =12.5; + Aprintf"%d,%o,%x\n", i,i,i); atprintf"%c,%d\n", c,c); -printf"%s\n","Hello C"); -printf"%f,%e,%g \ n", f,f,f); - -printf"12345678901234567890\n"); -printf"%5c,%5d,%10.5f,%10.5f\n", c,i,f,d); inprintf"12345678901234567890\n"); -printf"%-5c,%-5d,%-10.5f,%10.5f\n", c,i,f,d); to}
4. Format input function, scanf (), receive input from keyboard
1 //%d decimal integral type2 //%o Eight-input integer3 //%x hexadecimal integral type4 //%u unsigned form output integral type5 //%c one character6 //%s A string7 //%f A floating-point number (single-and double-precision)8 //%e Scientific Counting method output floating-point number9 //%ld Long Integer typeTen#include <stdio.h> One intMain () { A inti; - CharC; - floatF; thescanf"%d%c%f",&i,&c,&f); -printf"%d%c%f", i,c,f); -scanf"%d,%c,%f", &i,&c,&f);//input must be separated by commas -printf"%d%c%f", i,c,f); +}
Linux C Program (three)