我在函数 main 中声明了一个 char 变量 ope。 我通过 getchar 函数获取输入并存储在 ope 中。 现在我想清空变量,这样我就可以在 ope 中存储一些其他变量。 谁能告诉我该怎么做?? 我只想将输入连续存储在 ope 变量中。如果可以通过其他方式,请指导我。我将非常感激。
最佳答案
您可以像第一次使用它一样重用 getchar()
函数。
这是来自 cplusplus 的示例代码.
#include <stdio.h>
int main ()
{
char c;
puts ("Enter text. Include a dot ('.') in a sentence to exit:");
do {
c=getchar();
putchar (c);
} while (c != '.');
return 0;
}
关于c - 在c中消隐一个char变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3521266/