sure... here it is..basically im trying to create an amateur dictionary and the words is the file are seperated from the meanings by a " - " , and in case a word is repeated , the function returns the first value it found for example if i search for car it will return alacarte which comes before car in the text file. unless i explicitly search for "car -"
Code:
FILE *dict;
char buffer[MAX];
char input[MAX];
char *check;
char *found;
/*...*/
printf("Please enter a word to search for:\n");
fgets (input,MAX-1,stdin);
input[strlen(input)+1] = strcat(input , " -");
check = strtok(input, "\n");
fgets (buffer, MAX-1, dict);
while (!strstr(buffer, check))
{
fgets (buffer, MAX-1, dict);
count++;
found = strstr(buffer,check);
}
if(found)
printf( "\n%s\n", found );