【发布时间】:2016-12-08 06:11:51
【问题描述】:
这是一个电子词典程序。但是在这个程序中,dict[i][0]如何与空间进行比较。这将是真的。以及在最后一个if部分dict[i][0]如何比较到太空。请任何人解释。
#include<stdio.h>
#include<string.h>
int main(void)
{
char dict[][2][40] = {
"house","a place of dwelling",
"car","a vehicle",
"computer","a thinking machine",
"program","a sequence of instruction",
"",""
};
char word[80];
int i;
printf("Enter word: ");
gets(word);
i = 0;
while(strcmp(dict[i][0], "")){
if(!strcmp(word, dict[i][0])){
printf("Meaning: %s", dict[i][1]);
break;
}
i++;
}
if(!strcmp(dict[i][0], ""))
printf("Not in dictionary\n");
return 0;
}
【问题讨论】:
-
在线
"",""(在"program","a sequence of instruction"之后)你设置了列表的结尾; strcmp 正在寻找那个结束标记,所以它知道你在最后。你可以写"END"或者其他任何东西,只要你在两个地方都做同样的事情。