• 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("龄第二大的员工 姓名:%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");

    }

  • 相关阅读:
    【myEcplise2015】导入喜欢的主题
    【SVN】删除SVN上的历史资源路径和SVN上的历史用户信息
    【Linux】linux命令大全
    【Linux】在虚拟机上安装CentOS7
    Spring MVC+Mybatis 多数据源配置
    Spring 加载类路径外的资源文件
    OkHttp使用详解
    在虚拟机搭建JStrom
    在Windows下搭建RocketMQ
    解决confluence的乱码问题
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9094918.html
Copyright © 2020-2023  润新知