zoukankan      html  css  js  c++  java
  • 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");

    }

  • 相关阅读:
    跨浏览器的事件对象(EventUtil)
    原型 Object.create
    DC大牛的function扩展
    事件代理 proxy
    错误处理程序
    JQuery 插件
    关于ClownFish的问题
    C#拾遗
    Jquery技巧
    防盗链
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9094918.html
Copyright © 2011-2022 走看看