2

私は、英語の物語を読み、英語/エルフ語辞書を使用してそれをエルフ語に翻訳する翻訳/音訳プログラムに取り組んでいます。以下に示すコードの後に​​、受け取ったエラーについて説明します。

私はたくさんのコードを持っています。すべてを投稿する必要があるかどうかはわかりませんが、十分だと思うものを投稿します。私のコードが奇妙に見える場合は申し訳ありませんが、私は初心者です。

メインファイル、Translator と Dictionary の 2 つのクラスを含むヘッダーファイルおよびクラス関数を実装するためのcppファイルがあります。

辞書ファイルをdictFileNameに読み込み、英語の単語をenglishWordにコピーし、エルフの単語をelvishWordにコピーするコンストラクターがあります。

Translator::Translator(const char dictFileName[]) : dict(dictFileName)
{  
    char englishWord[2000][50]; 
    char temp_eng_word[50];
    char temp_elv_word[50];
    char elvishWord[2000][50];
    int num_entries;

    fstream str;

    str.open(dictFileName, ios::in);
    int i;

    while (!str.fail())
      {
       for (i=0; i< 2000; i++)
          {
          str>> temp_eng_word;
          str>> temp_elv_word;
          strcpy(englishWord[i],temp_eng_word);
          strcpy(elvishWord[i],temp_elv_word);
           }

        num_entries = i;

      }

      str.close();

}

メイン ファイルでは、英語の行がtoElvish関数に読み込まれ、単語の配列temp_eng_wordsにトークン化されます。

この toElvish 関数内で、別の関数を呼び出しています。これはtemp_eng_wordsを読み取り、エルフ語を返すことになっています。

char Translator::toElvish(char elvish_line[],const char english_line[]) 

{
    int j=0;

    char temp_eng_words[2000][50];
    //char temp_elv_words[2000][50]; NOT SURE IF I NEED THIS

    std::string str = english_line;
    std::istringstream stm(str);
    string word;
    while( stm >> word) // read white-space delimited tokens one by one 
    {
       int k=0;
       strcpy (temp_eng_words[k],word.c_str());

       k++;

    }   

    for (int i=0; i<2000;i++) // ERROR: out_s was not declared in this scope
    {
    Dictionary::translate (out_s,temp_eng_words[i]); // ERROR RELATES TO THIS LINE
    }

}

これは翻訳機能です:

char Dictionary::translate (char out_s[], const char s[])
{

 int i;

     for (i=0;i < numEntries; i++)
     {
        if (strcmp(englishWord[i], s)==0)
        break;
      }

        if (i<numEntries)
        strcpy(out_s,elvishWord[i]);
}

私の問題は、プログラムを実行すると、「*out_s was not defined in this scope*」というエラーが表示されることです。

これをすべて読んだ場合は、ありがとうございます。どんな提案/手がかりも大歓迎です。:)

4

1 に答える 1