• 实现大文件里的快速排序


    #define  _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <stdlib.h>
    
    struct csdn
    {
        char name[22];
        char password[43];
        char email[52];
    
    };
    int namemax = -1;
    int passmax = -1;
    int mailmax = -1;
    
    void init(struct csdn *pdata, char *str)
    {
        for (char *p = str; *p != '';p++)
        {
            if (*p=='#')
            {
                *p = '';
            }
        }
        strcpy(pdata->name, str);
        char *pstr1 = str + strlen(str) + 1;
        strcpy(pdata->password, pstr1);
        char *pstr2 = pstr1 + strlen(pstr1) + 1;
        strcpy(pdata->email, pstr2);
        //printf("%s,%s,%s", pdata->name, pdata->password, pdata->email);
    
    }
    
    void getmax(char *str)
    {
        for (char *p = str; *p != ''; p++)
        {
            if (*p == '#')
            {
                *p = '';
            }
        }
        int max1 = strlen(str);
        if (max1>namemax)
        {
            namemax = max1;
        }
        char *pstr1 = str + strlen(str) + 1;
        int max2 = strlen(pstr1);
        if (max2>passmax)
        {
            passmax = max2;
        }
        char *pstr2 = pstr1 + strlen(pstr1) + 1;
        int max3 = strlen(pstr2);
        if (max3>mailmax)
        {
            mailmax = max3;
        }
    
    }
    
    void readfiletxt()
    {
        FILE *pfr = fopen("Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\csdn.txt", "r");
        FILE *pfw = fopen("Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\csdn.bin", "wb");
        if (pfr==NULL)
        {
            return;
        } 
        else
        {
            while (!feof(pfr))
            {
                char str[256] = { 0 };
                fgets(str, 256, pfr);
                struct csdn csdn1;
                init(&csdn1, str);
                fwrite(&csdn1, sizeof(struct csdn), 1, pfw);//写入
                //getmax(str);
            }
    
        }
    
    
    
        fclose(pfr);
        fclose(pfw);
    }
    
    int getfilesize(char *path)
    {
        FILE *pf = fopen(path, "rb");
        if (pf==NULL)
        {
            return -1;
        } 
        else
        {
            fseek(pf, 0, SEEK_END);
            int length = ftell(pf);
            fclose(pf);
            return length;
        }
    
    }
    void main()
    {
        //struct csdn csdn1;
        //char str[100] = "bamyl # 7618595 # bamyl@etang.com";
        //init(&csdn1, str);
        //readfiletxt();
        //printf("%d,%d,%d", namemax, passmax, mailmax);
        int size=getfilesize("Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\csdn.bin");
        printf("%d", size);
        printf("
    %d", size / sizeof(struct csdn));
        FILE *pf = fopen("Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\csdn.bin", "rb+");
        while (1)
        {
            printf("请输入你要读取的第N个元素");
            int N;
            scanf("%d", &N);
    
            struct csdn csdn1 = {0};
            fseek(pf, sizeof(struct csdn)*(N - 1), SEEK_SET);//移动到这个位置
            fread(&csdn1, sizeof(struct csdn), 1, pf);
            printf("
    %s,%s,%s", csdn1.name, csdn1.password, csdn1.email);
    
    
        }
        fclose(pf);
    
        system("pause");
    }
  • 相关阅读:
    每天一点小进步(8):高效测试用例设计-XMind2TestCase
    每天一点小进步(7):Mqtt客户端理解
    每天一点小进步(6):postman使用指南
    每天一点小进步(5):python编码问题
    每天一点小进步(4): 推拉流协议初识
    每天一点小进步(3):yaml文件的相关知识点
    每天一点小进步(2):python 大文件处理
    每天一点小进步(1):lambda实现列表过滤&trim函数实现
    简单实现 随机发牌算法
    Linux学习(三)
  • 原文地址:https://www.cnblogs.com/sjxbg/p/5879331.html
Copyright © 2020-2023  润新知