首页 > 解决方案 > 在拼写校正器中检测到堆栈粉碎

问题描述

我将文件名作为这个函数的参数,我想比较两个 txt 文件并替换“文章”中的一些单词。但是在编译时发生堆栈粉碎检测错误。这段代码有什么问题?

    void fix_spelling_error(char* dictionary, char* article)
    {
    int articleCursor=0, compare, i=0, j, checkSpeller=0, ch;
    char word[100], sub[100];
    FILE *reader, *changer;

    reader = fopen(dictionary, "r");
    changer = fopen(article, "r+");

    if (changer != NULL && reader != NULL)
    {
        while(!feof(changer)
        fscanf(changer, "%s", word);


        while (!feof(reader))
        {
            fscanf(reader, "%s", sub);
            compare = strcmp(word, sub);
            if (compare == -1)
            {
                articleCursor = strlen(word);
                fseek(changer, -articleCursor, SEEK_CUR);
                strcpy(word, sub);
                fprintf(changer, "%s", word);
            }
        }
    fclose(reader);
    fclose(changer);
    }
}

标签: cstringfile-handling

解决方案


推荐阅读