12306 of leaked data, quick search for data with wood and you, programming implementation example, 12306 of your
</pre><pre code_snippet_id="576257" snippet_file_name="blog_20150110_2_9643624" name="code" class="objc">
/*************************************** * ******************************** All Rights Reserved (C) 2015, Wu Yingqiang ** file name: BigData. c * File ID: none * Content Abstract: Used to show how to find the specified character in Big Data * Other Description: none * Current version: V1.0 * Author: Wu yingqiang * completion date: 20150109 ** modification record 1: // modification history, including modification date, version number, modifier, and modification content * modification date: 20150109 * version number: V1.0 * modifier: wu yingqiang * modification content: create *************************************** * *****************************/# define _ CRT_SECURE_NO_WARNINGS # include <stdio. h> # in Clude <stdlib. h> # include <string. h> # include <time. h> char gPath [200] = "E: \ 12306data .txt"; # define N 119153 char str [100] = {0 }; // The string char ** gPtr = NULL; // second-level pointer storage address of the first-level pointer array /***************************** **************************************** ** function description: obtain the number of rows in the file * input parameter: none * output parameter: none * return value: number of rows-1-failure * Other Description: No * modified date version number modifier modified content * optional *------------------------------------------------------------------------------------ -- * 20150109 V1.0 Wuyq create ********************************** * ***********************************/int GetLineNum () {int iFileSize = 0; FILE * pfr = fopen (gPath, "r"); if (pfr = NULL) {return-1 ;}else {int I = 0; while (! Feof (pfr) {char strbuffer [256] = {0}; fgets (strbuffer, 256, pfr); // read a row of I ++ ;} iFileSize = ftell (pfr); printf ("file size: % f M \ n", 1.0 * iFileSize/1024/1024); fclose (pfr ); // close the file return I ;}} /*************************************** * ******************************** function description: initialize and read the file content to the memory * input parameter: none * output parameter: none * return value: none * Other Description: No * modified date version number modifier modified content * Others *------------------------------------------------------------------------------- ------- * 20150109 V1.0 Wuyq create ********************************** * ***********************************/void Init () {gPtr = (char **) malloc (sizeof (char *) * N); // dynamically allocates a pointer array memset (gPtr, '\ 0', sizeof (char *) * N); FILE * pfr = fopen (gPath, "r"); if (pfr = NULL) {printf ("initialization failed \ n"); return ;} else {for (int I = 1; I <= N; I ++) {char strbuffer [512] = {0}; fgets (strbuffer, 512, pfr ); // read a row of int length = strlen (strbuffe R); // obtain the length if (length! = 0) {gPtr [I] = malloc (sizeof (char) * (length + 1); // allocate memory for each pointer if (gPtr [I] = NULL) {printf ("\ nfail");} strcpy (gPtr [I], strbuffer); // copy the string // printf ("\ n % s ", gPtr [I]); // print the result} fclose (pfr ); // close the file }}/********************************* * ************************************ Function Description: release memory * input parameter: none * output parameter: none * return value: none * Other Description: No * modified date version number modifier content *-------------------------------------------------------------------------------- ------ * 20150109 V1.0 Wuyq create ********************************** * ***********************************/void Free () {for (int I = 1; I <= N; I ++) {free (gPtr [I]) ;}} /*************************************** * ******************************** function description: search data * input parameter: string to be searched, Which is input by the user * output parameter: none * return value: none * Other Description: No * modified date version number modifier modified content * limit * 2015010 9 V1.0 Wuyq create ************************************ * *********************************/void Search (char * str) {for (int I = 1; I <= N; I ++) {if (gPtr [I]! = NULL) {char * p = strstr (gPtr [I], str); // query if (p! = NULL) {printf ("the string to be searched, in line % d \ n", I); // print the result printf ("% s \ n ", gPtr [I]) ;}}} /*************************************** * ******************************** function description: main function * input parameter: none * output parameter: none * return value: none * Other description: there is no * modification date version number modifier change content * required * 20150109 V1.0 Wuyq creation ************************ **************************************** * ******/void main () {printf ("Total % d lines \ n", GetLineNum (); Init (); printf ("loaded \ n"); time_t start, end; time (& start); printf ("Enter the data you want to Search for: \ n"); scanf ("% s", str); Search (str ); time (& end); printf ("\ n total time % d S \ n", (unsigned int) (end-start); Free (); printf ("memory released \ n"); system ("pause ");}
Improvement in the later stage: the problem of Chinese characters.