Thread: Re : Programe for transalation

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Lightbulb Re : Programe for transalation

    Dear All,

    The following program is to translate a word from English to German. However, it can only translate one word each time, how can I modify the program to translate the whole sentence.
    E.g. input > dog no year -->output > Hund nein Jahr.

    Thanks for your help.

    #include <stdio.h>
    #include <string.h>

    char words[][2][40] = {
    "dog", "Hund",
    "no", "nein",
    "year", "Jahr",
    "drive", "fahren",
    "I", "Ich",
    "", ""
    };

    main()
    {
    char english[80];
    int i;
    printf("Enter English word: ");
    gets(english);

    /*look up the word */
    i = 0;
    /*search while null string not yet encountered */
    while(strcmp(words[i][0], "")) {
    if(!strcmp(english, words[i][0])){
    printf("German translation: %s", words[i][1]);
    break;
    }
    i++;
    }
    if(!strcmp(words[i][0], ""))
    printf("not in dictionary\n");
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    I've to go pretty soon, but I think this will do the trick...

    Code:
    int main()
    { 
     char english[80];
     char * pEnglish;
     int i; 
     printf("Enter English word: "); 
     gets(english); 
    
     // Tokenize the string using " "
     pEnglish = strtok (english, " ");
    
     while (strcmp (pEnglish, "") != 0)
     {
      /*look up the word */ 
      i = 0; 
      /*search while null string not yet encountered */ 
      while(strcmp(words[i][0], "")) { 
       if(!strcmp(pEnglish, words[i][0])){ 
        printf("German translation: %s", words[i][1]); 
        break; 
       }
       i++; 
      } 
      pEnglish = strtok (NULL, " ");
     } 
     if(!strcmp(words[i][0], "")) 
     printf("not in dictionary\n"); 
    }


    Ehhe, I misunderstood your question before, but I feel like this post I wrote is a pretty good insight in how one gets around the bigger problems of language translation...

    You have to write a parser.

    I don't really have experience with this, but I do know that this is basically the same problem as writing a program that can decide whether or not a sentence is in correct english.

    The idea is that to check the sentence, you have to split it up into groups of words. For example, we might split a sentence into a subject and a predicate, and then we have to figure out a way to figure out to test if the subject is correctly, and then check to see if the predicate is correct.

    And to check the subject (or predicate) you would also have to split that into smaller groups of words. For example, the subject might be split into an article, an adjective group, and a noun.

    At some point, you will have a group that you cannot split anymore. For example, articles cannot be split, since an article is just one word.

    Once you have the sentence divided up like this, you can (hopefully) just swap the groups around to get the right order.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to split long programe in small files
    By umeshjaviya in forum C Programming
    Replies: 11
    Last Post: 04-15-2008, 02:45 AM
  2. C programe Exercises?
    By RahulDhanpat in forum C Programming
    Replies: 10
    Last Post: 02-29-2008, 01:26 PM
  3. Got Into Trouble with simple programe.
    By RahulDhanpat in forum C Programming
    Replies: 6
    Last Post: 02-11-2008, 01:45 PM
  4. Programe error
    By colincsf in forum C Programming
    Replies: 8
    Last Post: 12-27-2002, 04:35 PM
  5. help needed with my programe
    By supernormal2 in forum C Programming
    Replies: 5
    Last Post: 12-11-2002, 10:57 PM