c - 错误: Stack around the variable 'ptemp' was corrupted

标签 c

我收到此错误:

( Stack around the variable 'ptemp' was corrupted. )

我的代码

list crea_lista(list l, FILE *fp, FILE *fp2){

    char ptemp[11];
    char ptemp2[11];
    element el;
    el.numero_volte=1;

    while(!feof(fp)){

        fscanf(fp,"%s",ptemp);

        while(!feof(fp2)){

            fscanf(fp2,"%s",ptemp2);

            if(strcmp(ptemp,ptemp2)==0){


                el.numero_volte=el.numero_volte+1;


            }

        }

        strcpy(el.parola,ptemp);
        l=insord(l,el);
        el.numero_volte=1;
        fflush(stdin);

        rewind(fp2);

    }

    return l;

}

如何解决这个问题?

最佳答案

您使用 11 个字符的内存初始化了 ptemp。如果从 fp 复制的字符串大于 11 个字符,fscanf 会将过去的 ptemp 写入其他内存。修复,要么仅复制 11 个字符,要么将 ptemp 的大小增加到您正在读取的字符串的最大大小(如果已知)。

关于c - 错误: Stack around the variable 'ptemp' was corrupted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31029888/

相关文章:

Javascript:请帮助我将此 C 函数转换为 Javascript

c - 了解用户何时按下向上/向下箭头

c - C 中的函数和变量作用域

c - 我需要帮助在简单的 C 代码中声明参数

c++ - 函数指针的取消引用是如何发生的?

c - 生成允许在给定范围内重复的随机数

无法在linux gcc中加载dll

分数高于 100 时无法显示 "Invalid Score. Please Re-enter"

c - 如何在C中按顺序执行子进程

c - 如何使用 C 中读取的函数显示文件内容?