数据结构存储

#include<stdio.h>
#include<stdlib.h>
#define MaxEmployees 100

typedef struct
    {       
        char name[20];
        double height;
        double salary;
    }employee;

typedef enum{FALSE,TRUE}BOOL;

void initemployeetable(void);
void listemployees(employee staff[], int nemployees);

static employee staff[MaxEmployees];
static int nemployees;

int main()
{
        initemployeetable();
        listemployees(staff, nemployees);
        return 0;
}
    
void initemployeetable(void)
{
    int i = 0;
    char ch;
    BOOL cont = TRUE;
    while (cont == TRUE)
    {
        printf("输入下一个人员信息吗?(y/n)");
        ch = getchar();
        if (ch == 'n' || ch == 'N')
        {
            cont = FALSE;
            nemployees = i;
            break;
        }
        printf("姓名");
        scanf("%s",&(staff[i].name));
        printf("身高");
        scanf("%f",&(staff[i].height));
        printf("收入");
        scanf("%f",&(staff[i].salary));
        i++;
    }
}

void listemployees(employee staff[], int nemployees)
{
     int i;
     for(i=1; i <= nemployees; i++)
     {
         printf("%s %f\n", staff[i].name, staff[i].height);
     }    
}

 

posted @ 2017-05-26 15:58  我不随便起名字  阅读(165)  评论(0编辑  收藏  举报