我试图创造C.这里一个简单的程序是有点儿什么我迄今为止的基础C输入问题
#include <stdio.h>
int main()
{
char input[256];
while(1)
{
printf("Input: ");
scanf("%s", input);
if(strcmp(input, "help") == 0)
printf("HELP STUFF HERE\n");
else if(strcmp(input, "1") == 0)
printf("2\n");
else if(strcmp(input, "test 1") == 0)
printf("Test 1\n");
else if(strcmp(input, "test 2") == 0)
printf("Test 2\n");
else
printf("Error");
}
return 0;
}
我有一些问题,但。首先我不能使用空格。如果我尝试测试1,我会得到错误的输出。我在第二个问题是,当它输出错误,它打印它到用户输入提示
这是我第一次见到这样的scanf格式说明符。它看起来像一个正则表达式。这甚至是标准吗? – 2011-02-25 02:11:36
嗯,我已经尝试了你给我的前两个建议,当我输入1时,它会反复打印2等。我会更多地关注fgets。 – AustinM 2011-02-25 02:11:41
@AustinM - 是的。 (当我第一次听到它时,我也持怀疑态度。) – 2011-02-25 02:13:51