我無法弄清楚爲什麼這段代碼直接跳到了模式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