我试图在无限while循环中接受字符串输入,每次都将字符串保存在同一个数组中,但我希望这个循环在我按下时终止Enter
代码看起来像这样:
int main()
{
char input[1000];
while (1)
{
scanf("%s",input);
if (input[0] == '\n'){ break; } //the problem is that scanf never gets the \n
else{...}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我写了一段代码来检测箭头键使用_getch();,我也希望检测esc键,但我实际上不知道我应该使用的数字是什么,所以任何帮助表示赞赏.
#include <conio.h>
#include <stdio.h>
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
int c = 0;
_getch();
switch ((c = _getch())) {
case KEY_UP:
printf("Up\n");
break;
case KEY_DOWN:
printf("Down\n");
break;
case KEY_LEFT:
printf("Left\n");
break;
case KEY_RIGHT:
printf("Right\n");
break;
default:
printf("Null\n");
break;
Run Code Online (Sandbox Code Playgroud)
每个箭头键是ascii代码224和定义的两个字符的组合(注意第一个_getch();),但我不知道对于转义键,我尝试搜索但没有找到它们,这些的完整列表将如此很有帮助.
谢谢.
我正在编写一个项目,我只需编写其中的一部分,问题是在if条件下我想调用别人写的函数.我有该功能的原型,但我没有它的身体.
所以链接器给我一个错误.是否可以在不注释函数调用的情况下编译代码?
这是我正在尝试编译的代码,任何帮助表示赞赏.
#include <stdio.h>
void foo(void);
int main(void)
{
char c = getchar();
if (c=='a'){ foo(); }
return 0;
}
Run Code Online (Sandbox Code Playgroud)