#define _crt_secure_no_warnings#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <process.h>//multithreading char g_path[200] = "i:\\baiduyundownload\\1 QQ envelope \\1E5-10 bit \\QQ envelope. txt"; #define N 84357584char str[100] = {0};char **g_pall = null;//Two-level pointer stores the address of the first-level pointer array 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, N, PFR);//read one line of i++;} Fclose (PFR);//close file return i;}} void Eatn (char *str) {while (*str! = ') ') {if (*str = = ' \ n ') {*str = '} ';} str++;}} void Init () {G_pall = (char * *) malloc (sizeof (char *) *n);//dynamically assigns an array of pointers memset (G_pall, ' + ', sizeof (char *) *n); FILE *PFR = fopen (G_path, "R"), if (PFR = = NULL) {printf ("Initialization failed"); return;} else{for (int i = 0; i < N; i++) {char strbuffer[79] = {0};fgets (strbuffer,, PFR);//reads a row of//printf ("%s,%d", Strbuffe R,strlen (Strbuffer)); Eatn (Strbuffer);//printf ("%s,%d", Strbuffer, strlen (Strbuffer)); int length = strlen (strbuffER);//To obtain the length if (length! = 0) {G_pall[i] = malloc (sizeof (char) * (length + 1));//each pointer allocates memory if (g_pall[i] = = NULL) {printf ("\ Nfail ");} strcpy (G_pall[i], strbuffer);//Copy String//printf ("\n%s", G_pall[i]);//print result}}fclose (PFR);//Close File}}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);//query if (P! = NULL) {j + +; printf ("\n%s", G_pall[i]);//Print Results}}}printf ("\nj=%d", j);//print slower than query}void main () {//printf ("%d", Getn ()), init ();p rintf ("Already loaded complete"); 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);p rintf ("\ n altogether%d S", (unsigned int) (End-start));} System ("Pause");}
Working with big data, programming implementation examples