getchar

    0熱度

    2回答

    我有這段代碼。我想要做的是等待用戶按'q'結束程序。 . ...starting few threads, which use fflush(stdout) (just saying...) . char n = 0; while (n != 'q') { n = getchar(); //tried to use scanf() here as well printf

    0熱度

    2回答

    我正在處理C中的矢量類,並且我在使用getchar()時遇到了一些問題。雖然我知道getchar()將返回一個整數/無符號字符,但它似乎行爲有所不同,當從getchar()的值分配給c中的一個動態創建的數組。我有一些代碼,我測試表明: #include <stdio.h> #include <stdlib.h> int main(){ char **ptr; ptr=cal

    1熱度

    1回答

    我感到困惑如何scanf的和的getchar手柄流不同,下面是一個示例代碼: while(scanf("%d", &input) != 1) { while((ch = getchar()) != '\n') { putchar(ch); } printf("\nThis is wrong\n"); } printf("That is r

    0熱度

    1回答

    #include<stdio.h> void main() { FILE *fp; char ch; fp = fopen("input.txt", "w"); printf("Enter data"); while ((ch = getchar()) != EOF) { putc(ch, fp); } fclose

    1熱度

    2回答

    #include <stdlib.h> #include <stdio.h> int main() { char word[100]; while (word != "hello") { system("clear"); printf("\nSay hello to me : "); scanf(" %s", word);

    -3熱度

    2回答

    爲什麼代碼直接在偶數時間獲取空數據?我不知道發生了什麼事。 非常感謝。 #include <stdio.h> #pragma warning(disable : 4996) void main() { int f, a = 10, b = 20; for (int i = 0; i < 5; i++) { char ch;

    -2熱度

    2回答

    我有以下程序: #include <stdio.h> #include <stdbool.h> #define MAX 100 //a) bool isPalyndrom(char c[], int cnt) { int i; char pal[MAX]; int j = 0; for (i = cnt - 1; i >= 0; i++) {

    0熱度

    3回答

    我想使用嵌套的switch語句爲用戶編寫一個菜單做選擇一些選項。第一個開關工作正常,並且嵌套的一個沒有。 在嵌套開關中,我總是以default選項結束,用戶不能選擇。 看起來變量d保持爲NULL,這就是使交換機在默認選項中結束的原因。什麼是防止用戶能夠鍵入一個字符,並從代碼分配值d? #include<mysql.h> #include<stdio.h> #include<stdlib.h>

    0熱度

    2回答

    我有兩個代碼問題,第一個問題是程序要我輸入兩次號碼,第二個問題是程序結束後立即關閉程序。 我試圖用getchar()聲明來阻止它,但它似乎並不奏效。 #include <stdio.h> int square(int); /*function prototype*/ main() { int x; /*defining the function*/ print

    -5熱度

    2回答

    在C,這是什麼做的盯着 int c; while ((c = getchar()) != EOF && c != '\n'); 我看到很多人都告訴我,它的while循環和所有的,爲什麼這麼多的併發症呢?爲什麼不能使用我在下面給出的代碼? gets(name); if(name == '\n'|| name == EOF) gets(name);`