大資料記憶體模型(二級指標)

來源:互聯網
上載者:User

標籤:

#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] = ‘\0‘;//最後為字串結束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, ‘\0‘, 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] = ‘\0‘;int strLength = strlen(str);if (strLength < 50){g_pp[i] = malloc(sizeof(char)*(strLength + 1));strcpy(g_pp[i], str);//拷貝到分配的記憶體}}fclose(pf);printf("載入完成\n");}}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);//找到返回地址,否則返回NULLif (p != NULL){puts(g_pp[i]);//列印}}}}}void main(){loadFromFile();while (1){char str[100] = { 0 };scanf("%s", str);search(str);//檢索}system("pause");}

 

大資料記憶體模型(二級指標)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.