结构体应用四

#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
",stu[i].name);
                printf("rank : %d
",stu[i].rank);
                printf("score : %5.1f
",stu[i].score);
                break;
            }
        }
        if(i>=NUM) printf("No found
");

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

    return 0;
}

一勤天下无难事。
原文地址:https://www.cnblogs.com/nowroot/p/15366562.html