#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #define path "1E~001.txt" char ** g_QQ;//存放在内存中的qq数据 int total_hang = 84357147;//标识一共多少行 int long_hang = 798;//标识有多少数据很长的数据 //读取一共有多少行数据 int read_total_hang() { int hang = -1; FILE *pf = fopen(path, "r"); if (pf) { hang = 0; printf("读取成功\n"); while (!feof(pf)) { char read_str[1024] = { 0 }; fgets(read_str, 1024, pf); read_str[1023] = ‘\0‘; int length = strlen(read_str); hang++; } return hang; } else { printf("读取失败\n"); return -1; } } //读取一共有多少超过长度的数据,长度如果大于100,就算长的数据 int read_long_hang() { int hang = -1; FILE *pf = fopen(path, "r"); if (pf) { hang = 0; printf("读取成功\n"); while (!feof(pf)) { char read_str[1024] = { 0 }; fgets(read_str, 1024, pf); read_str[1023] = ‘\0‘; int length = strlen(read_str); if (length >= 100) { hang++; } } return hang; } else { printf("读取失败\n"); return -1; } } //加载qq void load_qq() { g_QQ = calloc(sizeof(char *),total_hang - long_hang); FILE *pf = fopen(path, "r"); int i = 0; while (!feof(pf)) { char read_str[1024] = { 0 }; fgets(read_str, 1024, pf); read_str[1023] = ‘\0‘; int length = strlen(read_str); if (length < 100) { g_QQ[i] = calloc(sizeof(char), length); strcpy(g_QQ[i], read_str); i++; } } printf("载入成功\n"); } //查找数据 void find_qq(char *str) { for (int i = 0; i < total_hang - long_hang; i++) { if (strstr(g_QQ[i], str)) { printf("%s\n", g_QQ[i]); } } } void main() { load_qq(); while (1) { char qq[100]; scanf("%s", qq); find_qq(qq); } system("pause"); }