用指针数组指向5个人姓名,在程序中逐个比较,判断该学生是否存在
#include
char* search(char* s, char* name[], int n)
{
int i;
for (i = 0; i < n; i++)
{
if (strcmp(s, name[i]) == 0)
return name[i];
}
return NULL;
}
int main()
{
static char* name[5] = { "张三","李四","王五","周牛","小七" };
char s[10];
char* p;
scanf("%s", s);
p = search(s, name, 10);
if (p == NULL)
printf("not found!/n");
else
printf("%s is the here./n", p);
return 0;
}
共有 0 条评论