處理大資料, 編程實現樣本

來源:互聯網
上載者:User

標籤:

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include<string.h>#include <time.h>#include <process.h>//多線程char g_path[200] = "I:\\BaiduYunDownload\\1億QQ信封\\1E5-10位\\QQ信封.txt";#define  N   84357584char str[100] = { 0 };char **g_pall = NULL;//二級指標儲存一級指標數組的地址int getN(){FILE *pfr = fopen(g_path, "r");if (pfr == NULL){return -1;}else{int i = 0;while (!feof(pfr)){char strbuffer[256] = { 0 };fgets(strbuffer, 256, pfr);//讀取一行i++;}fclose(pfr);//關閉檔案return i;}}void eatN(char *str){while (*str != '\0'){if (*str == '\n'){*str = '\0';}str++;}}void init(){g_pall = (char **)malloc(sizeof(char *)*N);//動態分配一個指標數組memset(g_pall, '\0', sizeof(char *)*N);FILE *pfr = fopen(g_path, "r");if (pfr == NULL){printf("初始化失敗");return;}else{for (int i = 0; i < N ; i++){char strbuffer[79] = { 0 };fgets(strbuffer, 79, pfr);//讀取一行//printf("%s,%d", strbuffer,strlen(strbuffer));eatN(strbuffer);//printf("%s,%d", strbuffer, strlen(strbuffer));int length = strlen(strbuffer);//求擷取長度if (length != 0){g_pall[i] = malloc(sizeof(char)*(length + 1));//每個指標分配記憶體if (g_pall[i] == NULL){printf("\nfail");}strcpy(g_pall[i], strbuffer);//拷貝字串//printf("\n%s", g_pall[i]);//列印結果}}fclose(pfr);//關閉檔案}}void search(char *str){int j = 0;for (int i = 0; i < N-1; i++){if (g_pall[i] !=NULL){char *p = strstr(g_pall[i], str);//查詢if (p != NULL){j++;printf("\n%s", g_pall[i]);//列印結果}}}printf("\nj=%d", j);//列印速度慢於查詢}void main(){//printf("%d", getN());init();printf("已經載入完成");while (1){//time_t start, end;time(&start);//int i = 0;//scanf("%d", &i);//printf("\n%s", g_pall[i]);scanf("%s", str);search(str);time(&end);printf("\n一共%d S", (unsigned int)(end - start));}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.