0

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..

DrKoch
  • 9,556
  • 2
  • 34
  • 43
  • 2
    Get a good book of C programming to your shelf. Read and accept this http://stackoverflow.com/tour. Focus on "Get answers to practical, detailed questions". – harper Mar 31 '15 at 06:25
  • You are in luck. This question is answered their as well [**Using C, to print out an array from textFile**](http://stackoverflow.com/questions/29358127/using-c-to-print-out-an-array-from-textfile). Take a look. (I know, I just answered with the `English` and `TextSpeak` struct...) Ah, but I think you already know that. That's were my `#define MAXL 128` came from ... – David C. Rankin Mar 31 '15 at 06:31

0 Answers0