我无法弄清楚为什么这段代码直接跳到了模式5.我已经看了好几遍,而我只是没有看到它。任何帮助将不胜感激。我猜测它与我初始化数组的方式以及我比较它们的方式有关。我曾尝试使用'strcmp',目前正试图比较直接阵列位置。这两个都编译成功,但我似乎无法让它工作。C编程 - 将常量字符数组与用户输入进行比较
char one[3][3];
const char *pattern[] = {"p1","p2","p3","p4","p5"};
printf("%s Commands are {'p1', 'p2', 'p3', 'p4', 'p5'\n", prompt);
printf("Enter your first pattern choice: ");
scanf("%2s",one[0]);
printf("Enter your second pattern choice: ");
scanf("%2s",one[1]);
printf("Enter your third choice: ");
scanf("%2s",one[2]);
for (int i = 0; i < 2; i++)
{
do{
if (one[i] == "p1")
{
printf("\n1.1");
patternOne();}
else if (one[i] == "p2")
{
printf("\n1.2");
patternTwo();}
else if (one[i] == "p3")
{
printf("\n1.3");
patternThree();}
else if (one[i] == "p4")
{
printf("\n1.4");
patternFour();}
else
{
printf("\n1.5");
patternFive();
}
}
while (i < 3);
你不知道如何比较字符串。查找'strcmp()'(然后删除这个问题) – John3136 2015-02-23 03:17:53