THE MAIN FILE
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> #define filesize 10000 #define segsize 1000 char *ReadFile() { FILE *fp; char *listp; char list[filesize]; int numread; ///Reading file into buffer and assigning pointer to array if( (fp = fopen( "e:\\temp\\tur.txt", "r" )) != NULL ); { numread = fread( list, sizeof( char), filesize, fp ); listp=&list[0]; fclose( fp ); } ///Returning w pointer to buffer return(listp); } int StrSearch(char *str,int token) { int n; for (n=0;*str !=token;str++) n++; ///returning w lenght of string return(n); } int MakeAnswer(char *listp,char *inputstr) { char *maskword=malloc(segsize); char *result=malloc(segsize); char *answer=malloc(segsize); char *final=malloc(segsize); char *loc=malloc(segsize); char answnum; int lenght; int res=0; loc=listp; ///search until word match is found while (res!=1) { ///maskout a word from a segment lenght=StrSearch(loc,'#'); ////maskout word strncpy(maskword,(loc+lenght)+1,StrSearch(loc,'#')+2); ///scan the input for this word and return w pointer to its answers result=strstr(inputstr,maskword); answnum='1'; if (result>NULL) { answer=strstr(loc,maskword); lenght=StrSearch(answer,answnum)+1; strncpy(final,answer+lenght,StrSearch(answer+lenght,'%')); printf("%s\n",final); res=1; } ///store position of next word in loc loc=loc+lenght+2+StrSearch(loc+lenght+1,'#'); loc=loc+StrSearch(loc,'#'); ///reset parameters lenght=0; maskword=""; } return(0); } int main() { char inp[50]; gets(inp); MakeAnswer(ReadFile(),inp); getch(); return(0); }