天行健,君子以自强不息!!QQ:68660681
#include<stdio.h>
#include<string.h>
char *st1[8]={"99070101","99070102","99070103","99070104","99070105","99070106","99070107"};
int SeqSearch(char **str1,char k[9])
{
int i,j;
char **p;
p=st1;
for(i=0;i<7;i++)
if(!strcmp(*(p+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();
}
为了程序简洁和便于理解使用了字符串比较程序strcmp();
程序中注意一、二维数据的使用
[CODE]
#include<stdio.h>
#include <string.h>
char *st1[8]={"99070101","99070102","99070103","99070104","99070105","99070106","99070107"};
int SeqSearch(char **p,char k[9])
{
int i;
for(i=0;i<8;i++)
if(strcmp(*(p+i),k) == 0)
return(i);
return(-1);
}
int main()
{
int k;
char ch[8];
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");
}
getch();
}
[/CODE]