【发布时间】:2014-01-28 21:37:39
【问题描述】:
这是我的代码
const char *s[5];={"abcd","efgh","ijkl","mnop","qrst"};
char a[4];
while (1)
{
scanf("%4s",&a);
//compare a with s array
if(/*a exists in s*/)
printf("it is ok");
if(/*a does not exist in s*/)
printf("it is not ok");
}
例如,当我输入“dcba”时,我想看到“它不正常”。当我输入“efgh”时,我想看到“没关系”。
【问题讨论】:
-
scanf需要char *和%4s,而不是char(*)[4]。如何进行比较也很重要。 -
您可以编辑所有内容以达到我的需要。
-
当
"%4s",需要char a[5]; -
scanf 采用指向变量的指针,
int a;将是scanf("%d", &i);。但是,由于您的案例中的 char a 指向数组是否开始,所以它在没有引用的情况下使用,scanf("%s", a)就像那样! -
bsearch可以在数组排序后使用。