惟有学习不断的学习!
[此贴子已经被作者于2007-7-8 8:28:53编辑过]
或者是也可以
#include<stdio.h>
#include<string.h>
char *st1[8]={"99070101","99070102","99070103","99070104","99070105","99070106","99070107"};
int SeqSearch(char *k)
{
int i,j;
for(i=0;i<7;i++)
if(!strcmp(st1[i],k)) return i;
return(-1);
}
int main()
{
int k;
char ch[9];
printf("input your search number:\n");
scanf("%s",ch);
k=SeqSearch(st1,ch);
if(k+1)
{
printf("\t number\n");
printf("\t%s\n",st1[k]);
}
else
printf("NOT FIND!\n");
getchar();
getchar();
}
或者是 重点注意对数组元素的引用
#include<stdio.h>
#include<string.h>
char *st1[8]={"99070101","99070102","99070103","99070104","99070105","99070106","99070107"};
int SeqSearch(char *k)
{
int i,j;
for(i=0;i<7;i++)
if(!strcmp(*(st1+i),k)) return i;
return(-1);
}
int main()
{
int k;
char ch[9];
printf("input your search number:\n");
scanf("%s",ch);
k=SeqSearch(ch);
if(k+1)
{
printf("\t number\n");
printf("\t%s\n",st1[k]);
}
else
printf("NOT FIND!\n");
getchar();
getchar();
}