当前位置:网站首页>C language ---getchar() and putchar()

C language ---getchar() and putchar()

2022-06-26 13:54:00 cxxbb

putchar() and getchar() Are used for input and output of characters

putchar()-- Output a character

getchar()-- Read characters from the cache , Call once getchar() Just read one character

When the program calls getchar() when , The program waits for the user to enter characters from the keyboard , The input character will be put into the buffer first , Wait until the user presses enter , Press each getchar() and scanf() Assign a character value in the order of .

#include<stdio.h>
int main()
{
    char B0,B1,B2;
    printf("press a key and then press enter:");
    B0=getchar();
    scanf("%c",&B1);
    B2=getchar();
    printf("%c",B1);
    putchar(B2);
    putchar(B0);
    return 0;
}

Results, :

press a key and then press enter:FGH
GHF

原网站

版权声明
本文为[cxxbb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170511578261.html