zoukankan      html  css  js  c++  java
  • 实现大文件里的快速排序

    #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");
    }
  • 相关阅读:
    Linux系统挂载NTFS移动硬盘
    ActiveReport报表开发谈谈ActiveReport的中文化问题
    硬件接口开发之USB电话录音盒来电显示
    如何使用正则表达式进行QQ校友的数据采集
    硬件接口开发之Modem来电显示
    关于MSHTML控件使用的问题
    【转】ISession接口介绍
    发送带嵌入图片邮件之SMTP实现和ESMTP实现
    C#进行MapX二次开发之地图搜索
    Database2Sharp混淆处理之经验分享(国庆专辑,祝福我们的祖国)
  • 原文地址:https://www.cnblogs.com/sjxbg/p/5879331.html
Copyright © 2011-2022 走看看