getchar

    2熱度

    2回答

    考慮下面的代碼: #include<stdio.h> int main(){ char c; while((c=getchar()) != EOF) printf("%c\n",c); return 0; } 我給輸入爲:喜^ Z 輸出爲: h i (an arrow pointing towards left) [對不起,我無法找到上述箭頭的字符。 ] 有人可以

    3熱度

    4回答

    我正在參加關於「C」的培訓課程並遇到問題。這很難解釋,所以我會發布代碼。這是訓練語法,所以不要問我爲什麼這樣做。當這兩個段塊都在main()中運行時,第二個塊的行爲不像在main()中單獨存在。我已經嘗試了幾個IDE認爲它可能是一個錯誤。 /* First Segment Block */ int c; printf("Type a letter: "); c = getchar(); p

    1熱度

    1回答

    void getInputData(void) { char c = 0; while (c != 'x') { printf("Enter a letter:"); fflush(stdout); c = getchar(); printf("You entered: %c \n",c); fflush(stdout

    4熱度

    4回答

    我只是問在這段代碼中getchar做了什麼,它是如何工作的?我不明白爲什麼getchar會影響代碼,對我來說,好像它只是獲取值,但沒有任何值正在完成。 int c=0; while (c>=0) { scanf("%d", &c); getchar(); }

    -3熱度

    1回答

    printf("%3o\t%2x\t%3d\t%c\n", c = getchar(), c, c, c); 我得到一個警告,說「無序修改和訪問'c'[-Wunsequenced]」。錯誤很容易修復;我所要做的就是將getchar()與printf()分開,但我只想更好地理解該指令爲什麼會產生警告,以及如果我實際運行它會出現什麼問題。 這與使用CPP宏實現printf()的可變長度參數列表有什

    4熱度

    1回答

    所以在代碼中,我正在讀來自用戶的選項,然後再決定是否執行規定動作以下位: printf("Do you want to execute %s: ", exe); char input = getchar(); if (input == 'y') { return execute(exe); } return 0; 我遇到的問題是該行char input = getchar(

    1熱度

    1回答

    有人可以解釋我的代碼嗎? d不會總是等於c?我想我真的沒有得到這個getchar()函數。爲什麼d總是等於`c? #include<stdio.h> void test(int c); int main(void) { int c; while ((c = getchar()) != EOF) { test(c); }

    3熱度

    2回答

    爲什麼下面的代碼片斷的第一輸入?: #include <stdio.h> int main() { int a; int b; printf("Enter a first value :"); a = getchar(); printf("You entered: "); putchar(a); printf("\n E

    0熱度

    3回答

    我在C中創建一個菜單驅動的程序,我必須要求用戶輸入,然後在程序中只使用輸入的第一個字符。除了下面的代碼之外,我還嘗試使用#define MAX_CHAR 1並在while循環中使用它代替EOF,等等。 #include <stdio.h> #include <string.h> #include <stdlib.h> void print_menu(); void uppercase(c

    -1熱度

    1回答

    好的,你好。我的意圖是要求用戶輸入文件名並使用管道機制打開文件。現在我只有這個代碼。如何實際執行管道以及存儲信息的位置 - .myprog < text,其中text是getchar應該採用的輸入。在此先感謝 #include <stdio.h> #include <stdlib.h> int main(void) { char input; input=getchar