zoukankan      html  css  js  c++  java
  • 大数据内存模型(二级指针)

    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <Windows.h>
    #include <memory.h>
    #define path "E:\杂乱test\内存大数据模型\1E~001.txt"
    char **g_pp;
    int imax = 8435714;//标识有多少行
    int jmax = 20027;//标识最宽
    
    int getJmax()
    {
    	int width = -1;
    	FILE *pf = fopen(path, "r");//读文件打开路径
    	if (pf == NULL)
    	{
    		printf("文件打开失败");
    	}
    	else
    	{
    		while (!feof(pf))
    		{
    			char readStr[30000] = { 0 };
    
    			fgets(readStr, 30000, pf);//读取一行
    			readStr[29999] = '';//最后为字符串结束
    			int strLength = strlen(readStr);
    
    			if (strLength > width)
    			{
    				width = strLength;
    			}
    		}
    		fclose(pf);//关闭
    	}
    
    	return width;
    }
    
    int getImax()
    {
    	int hang = -1;
    	FILE *pf = fopen(path, "r");//读文件打开路径
    	if (pf == NULL)
    	{
    		hang = -1;
    		printf("文件打开失败");
    	}
    	else
    	{
    		while (!feof(pf))
    		{
    			char readStr[1024] = { 0 };
    
    			fgets(readStr, 1024, pf);//读取一行
    
    			hang++;
    		}
    		fclose(pf);//关闭
    	}
    
    	return hang;
    }
    
    void loadFromFile()
    {
    	g_pp = (char **)malloc(sizeof(char*)*imax);//分配指针数组 多少行
    	memset(g_pp, '', sizeof(char*)*imax);
    	FILE *pf = fopen(path, "r");
    	if(pf == NULL)
    	{
    		printf("文件打开失败");
    		return;
    	}
    	else
    	{
    		for (int i = 0; i < imax;i++)
    		{
    			char str[1024] = { 0 };
    			fgets(str, 1024, pf);//按行读取
    			str[1023] = '';
    			int strLength = strlen(str);
    			if (strLength < 50)
    			{
    				g_pp[i] = malloc(sizeof(char)*(strLength + 1));
    				strcpy(g_pp[i], str);//拷贝到分配的内存
    			}
    		}
    		fclose(pf);
    		printf("载入完成
    ");
    	}
    }
    
    void search(char *str)
    {
    	if (g_pp != NULL)
    	{
    		for (int i = 0; i < imax; i++)
    		{
    			if (g_pp[i] != NULL)
    			{
    
    				char *p = strstr(g_pp[i], str);//找到返回地址,否则返回NULL
    				if (p != NULL)
    				{
    					puts(g_pp[i]);//打印
    				}
    			}
    		}
    	}
    }
    
    void main()
    {
    	loadFromFile();
    	while (1)
    	{
    		char str[100] = { 0 };
    		scanf("%s", str);
    		search(str);//检索
    	}
    
    	system("pause");
    }
    
  • 相关阅读:
    程序猿之没事瞎吐槽
    iOS 打印日志的保存 (一)
    Xcode4.5 本地化,多语言设置
    css3渐变画斜线 demo
    关于JavaScript的一些记录
    Windows 10 自带输入法(微软拼音)繁体简体切换快捷键
    ng-class用法小记
    基于vue监听滚动事件,实现锚点链接平滑滚动
    总结继承的几种方式
    浅谈jQuery的内部框架结构,操作
  • 原文地址:https://www.cnblogs.com/xiaochi/p/5176327.html
Copyright © 2011-2022 走看看