Linux C Program (three)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.