首页 > 代码库 > C快速复习

C快速复习

#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    float input;
    bool isTrue = (scanf("%f",&input) == 1);
    while(isTrue)
    {
        printf("it‘s %.d\n",(int)input);//输入的小于1就不会打印出来
        isTrue = (scanf("%f",&input) == 1);
    }
}
/*当只需获取一个输入时,可以向下面的这样做*/
#include <stdio.h>
int main(void)
{
    char boop;
    while(scanf("%c",&boop) == 1)
    {
        while(getchar() != ‘\n‘)
            continue;
        printf("It‘s %c",boop);
    }
} 
//等同于下面的程序

#include <stdio.h>
int main(void)
{
    char boop;
    while(gets(&boop))
    {
        printf("It‘s %c",boop);
    }
}

本文出自 “天才的实力” 博客,转载请与作者联系!

C快速复习