首页 > 其他 > 详细

93管理系统之查询功能

时间:2018-05-27 10:20:38      阅读:188      评论:0      收藏:0      [点我收藏+]

查询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");

}

93管理系统之查询功能

原文:https://www.cnblogs.com/xiaodaxiaonao/p/9094918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!