我正在编写一个需要字符串输入的程序,但是当我扫描它时,它的行为不像字符串应该的那样。
这里是相关代码:
char cside[5];
printf("Enter the side the car is on:\n");
scanf("%s", &cside);
printf("%s\n", cside);
if (cside == "left" && cside == "right" && cside == "Left" && cside == "Right")
{
if (cside == "left" || cside == "Left")
{
printf("Enter the length of the car:\n");
scanf("%d", &cl);
lqueue_tenqueue(hLQ, cl);
}
else if (cside == "right" || cside == "Right")
{
printf("Enter the length of the car:\n");
scanf("%d", &cl);
rqueue_tenqueue(hRQ, cl);
}
else
{
printf("That is not a valid input.\nEnter the side the car is on:\n");
scanf("%s", &cside);
}
}
它甚至跳过最后一个else
语句。我有printf("%s\n", cside);
语句,因此可以确定该字符串是我认为的样子,那么这是怎么回事?