0

这是一段代码,我将带有空格的字符串从文本打印到另一个 txt 文件中。我有一个代码列表,我必须用正确的代码切换特定的字符串。代码在一个数组中。我无法使编码功能起作用。Fprintf 打印代码后跟基本字符串。我想跳过这些字符串。我只需要打印代码。我在哪里错过了什么?

int m;
file = fopen("input.txt", "r" );
while (fscanf(file, "%s", word) != EOF ) {        
    for (m=0; m<j; m++) {                           
        if (strcmp(word, particularwords[m]) == 0) {     
            fprintf(outfile, "%s ", code[m]);
            continue;                     
        }
    }
fprintf(outfile, "%s ", word);
}
4

1 回答 1

1

继续是问题。

它继续for循环而不是while。

这是我认为应该的:

int m;
file = fopen("input.txt", "r" );
while (fscanf(file, "%s", word) != EOF ) {        
    for (m=0; m<j; m++) {                           
        if (strcmp(word, particularwords[m]) == 0) {     
            fprintf(outfile, "%s ", code[m]);
            break; //for                     
        }
    }
    if(m==j){ //word not found!
       fprintf(outfile, "%s ", word);
    }
}
于 2013-10-30T14:14:30.187 回答