结构体应用四

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM 4

struct student
{
    int rank;
    char* name;
    float score;
};

struct student stu[] =
{
    3,"Tom", 89.3,
    4,"Mary",78.2,
    1,"Jack",95.1,
    2,"Jim", 90.6,
};

int main()
{
    char str[10];
    int i;
    do
    {
        printf("Enter a name:");
        scanf("%s",str);
        for(i=0;i<NUM;i++)
        {
            if(strcmp(stu[i].name,str)==0)
            {
                printf("name : %8s\n",stu[i].name);
                printf("rank : %d\n",stu[i].rank);
                printf("score : %5.1f\n",stu[i].score);
                break;
            }
        }
        if(i>=NUM) printf("No found\n");

    }while(strcmp(str,"0")!=0);

    return 0;
}

 

posted @ 2021-10-04 16:03  卷哭你  阅读(64)  评论(0编辑  收藏  举报