일반 단어를 해적 등가 (hi = ahoy)로 번역하기위한 프로그램을 작성 중입니다.텍스트 파일에서 개별 단어 읽기 및 번역 - C
두 개의 문자열 배열을 사용하여 사전을 만들었으며 이제는 input.txt 파일을 번역하여 output.txt 파일에 넣으려고합니다. 나는 출력 파일에 쓸 수 있지만 그것은 번역 된 첫 단어를 계속해서 새로운 행에 씁니다.
많은 읽기/수색과 내가 말할 수있는 것에서 fscanf()
을 사용하여 입력 파일을 읽는 것이 이상적이지는 않지만 사용하기에 더 좋은 기능이 무엇인지 알 수 없습니다. 나는 단어별로 파일 단어를 읽어야하고 (스페이스로 구분) 각 구두점을 읽어야한다. 당신이 다른 영어 단어에 일치 시작으로,
void Translate(char inputFile[], char outputFile[], char eng[][20], char pir[][20]){
char currentWord[40] = {[0 ... 39] = '\0'};
char word;
FILE *inFile;
FILE *outFile;
int i = 0;
bool match = false;
//open input file
inFile = fopen(inputFile, "r");
//open output file
outFile = fopen(outputFile, "w");
while(fscanf(inFile, "%s1023", currentWord) == 1){
if(ispunct(currentWord) == 0){
while(match != true){
if(strcasecmp(currentWord, eng[i]) == 0 || i<28){ //Finds word in English array
fprintf(outFile, pir[i]); //Puts pirate word corresponding to English word in output file
match = true;
}
else {i++;}
}
match = false;
i=0;
}
else{
fprintf(outFile, &word);//Attempt to handle punctuation which should carry over to output
}
}
}
정말 고마워요! 바로 그걸 고정시켰다. 또한 제 코드가 왜 작동하지 않는지에 대해 설명해 주셔서 감사합니다. 앞으로이 실수를 피할 수 있기를 바랍니다. – bullinka