c++ - Translation/Transliteration problems -
i working on translation/transliteration program, reads english story, , translates elvish, using english/elvish dictionary. after code shown below, explain error receive.
i have lot of code, not sure if should post all, post think should sufficient. apologies if code seems bizarre - beginner.
there main file, header file 2 classes: translator , dictionary, , cpp file implement class functions.
i have constructor reads in dictionary file dictfilename , copys english words englishword, , elvish words 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()) { (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(); }
in main file, english lines read toelvish function, , tokenized array of words, temp_eng_words.
within toelvish function, calling function; translate, reads in temp_eng_words , supposed return elvish 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 need std::string str = english_line; std::istringstream stm(str); string word; while( stm >> word) // read white-space delimited tokens 1 one { int k=0; strcpy (temp_eng_words[k],word.c_str()); k++; } (int i=0; i<2000;i++) // error: out_s not declared in scope { dictionary::translate (out_s,temp_eng_words[i]); // error relates line } }
this translate function:
char dictionary::translate (char out_s[], const char s[]) { int i; (i=0;i < numentries; i++) { if (strcmp(englishword[i], s)==0) break; } if (i<numentries) strcpy(out_s,elvishword[i]); }
my problem when run program, error '*out_s not declared in scope*'.
if have read of this, thanks; suggestions/clues appreciated. :)
Comments
Post a Comment