C语言的输入输出各种常见问题(printf,scanf,getchar,getch,getche)

C语言输入输出的各种常见问题

下面是我编写的代码,代码里的注释都是我在复习这次C语言输入输出所写的,英文,,,emm,我在有道词典翻译的,一般没啥大问题,有啥问题欢迎提问,有啥错误希望各位大佬指出纠正。

/*
programmer: yang yang chen
time:2020/8/12
*/

#include<stdio.h>
#include<conio.h>

int main( void ){
    int number;
    float number1;
    int a, b;
    char c;

    printf( "please enter a character:\n");
    c = getchar();
    printf( "c(getchar): %c\n", c);
    printf( "please enter a character:\n");
    c = getch();
    printf( "c(getch): %c\n", c);
    printf( "please enter a character:\n");
    c = getche();
    printf( "\nc(getche): %c\n", c);

     printf( "please enter the int number and float number1:\n");
    a = scanf( "%d%*c%f", &number, &number1 );
    printf( "\na: %d", a);
    printf( "Octal form: %#o\nDecimal form: %d\nHexadecimal form: %#x\n", number, number, number );
    printf( "Unsigned integer form: %u\n06: %06d\n", number, number );
    printf( "5.2f: %5.2f\nE: %e\n" , number1, number1 );
    b = printf( "*: %*f\n", number, number1);
    printf( "%d\n", b);
    printf( "-md: %-10d\nmd: %10d\n", number, number );
    return 0;
}

/*Conclusion

printf():
        %d & %i: 
        Output in decimal.

        %ld: 
        Output long integer data.

        %md & %0md & %-md & -0md: 
        The m represents the output field width, insufficient padding of space or zero,
        the symbol indicates the left hand side.

        %u & %U:
        Output an unsigned integer.

        %c:
        Output a character.

        %f:
        Output a real number.

        %.mf:
        Keep m bits for the output real numbers.

        %o & %#o:
        Output in octal integer from, the # express the zero.

        %s:
        Output string.

        %x & %X & %#x &%#X:
        Output an integer in hexadecimal format, case sensitive, and the # express the zero.

        %e:
        Output real numbers as exponents.

        %*:
        Jump over.

scanf():
        %*: Accept but do not store.


return value problem:
        printf(): Returns the number of characters printed.
        scanf(): Returns the number of normal input objects.

getchar & getch & getche:
    1. getchar in stdio.h.
    2. getch & getche in conio.h.
    3. getchar: return a character, displayed on the screen, and end with a line break.
    4. getch: return a character, not displayed on screen, and don't wrap.
    5. getche: return a character, displayed on screen, and don't wrap.

*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值