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