I have to create a code where you ask the user what phrase they want to search in a text to be translated. The phrase they input is supposed to be stored into an array, each word in the phrase is added to the array separated by a space. The program then searches the textfile to find the matching phrase. If the exact phrase is found, the exact phrase is translated. If the exact phrase is not found, it is broken into individual words and is translated individually. The words not found are left as is and the entire translated phrase is printed.
The phrases are stored in a textfile like this one:
hello
ey
how are you
hw u doin
what
wut
laugh out loud
lol
The first word is the word we will translate, meaning the translation is the line after.
I'm also using structs to do this. This is what I have so far, but it is not searching the file I want properly.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXL 128
typedef struct
{
char *English;
char *TextSpeak;
}Pair;
void main() {
FILE *infile=fopen("dictionary.txt","r");
int line_num = 1;
char inputArrray[];
int find_result = 0;
char temp[512];
printf("Enter the English phrase to search in dictionary: \n");
scanf(" %d", &inputArray[i]);
while(fgets(inputArray, 512, infile) != NULL) {
if((strcmp (inputArray, str)) != NULL) {
printf("A match found on line: %d\n", line_num);
printf("\n%s\n", inputArray[i]);
}
line_num++;
}
}
Now how would I associate my struct into this, and should I use strcmp or something like starts..
Any help would be appreciated for this program..