c语言 查找学生信息
发布网友
发布时间:2022-04-29 17:43
我来回答
共1个回答
热心网友
时间:2023-10-14 06:46
很简单的程序,帮你写个范例,适当改改就能执行了。
struct Student
{
int id;
char* name;
int score;
}
Student* findStudent(Student* s, int count, char* name)
{
for(int i = 0; i < count; i++)
{
if(strcmp(name, s[i].name) == 0)
{
return s+i;
}
}
return NULL;
}
void main()
{
Student ss[5];
/////初始化Student数组
Student* s = findStudent(ss, 5, "name");
if(s == NULL)
{
printf("cannot find a valid student named '%s'", "name");
}
else
{
printf("find him/her");
}
}