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);
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章