93管理系统之查询功能

查询txt中年龄第二大的员工信息,并输出.
一个学生管理系统:
添加学生信息
删除学生信息
查询学生信息

 

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct work {
char* name;
int age;
char* company;
};
work*give = NULL;

void main() {
FILE*read = fopen("1", "r");
if (!read) {
printf("文件为空");
system("pause");
return;
}


int kong = NULL;
int xiaomiao = NULL;
int count = NULL;

while (!feof(read)) {
char shuju[50] = { NULL };

fgets(shuju, sizeof(shuju), read);
int shaomiao = ftell(read);
if (shaomiao != kong) {
count++;
give = (work*)realloc(give, count * sizeof(shuju));
char*temp = strtok(shuju, ",");
give[count - 1].name = (char*)calloc(strlen(temp) + 1, sizeof(char));
strcpy(give[count - 1].name, temp);
temp = strtok(NULL, ",");
give[count - 1].age = atoi(temp);

temp = strtok(NULL, "NULL");
give[count - 1].company = (char*)calloc(strlen(temp) + 1, sizeof(char));
strcpy(give[count - 1].company, temp);
}
}

work*a = give;
work*b = give;
for (size_t i = 0; i < count; i++)
{
if (give[i].age > a[0].age) {
b = a;
a = &give[i];
}
else if (give[i].age > b[0].age && give[i].age < a[0].age) {
b = &give[i];


}

}
printf("龄第二大的员工\n姓名:%s 年龄 : %d 工作单位 : %s", b[0].name, b->age, b->company);
for (size_t i = 0; i < count; i++)
{
free(give[i].name);
free(give[i].company);

}
fclose(read);

system("pause");

}

posted @ 2018-05-27 00:47  随意就好欧巴  阅读(261)  评论(0编辑  收藏  举报