标题:[新手]结束时报错-Run-Time Check Failure #2 #0
取消只看楼主
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
结帖率:100%
已结贴  问题点数:20 回复次数:2 
[新手]结束时报错-Run-Time Check Failure #2 #0
这两天看了指针和结构体之后弄的

求解一下,程序结束时的报错:Run-Time Check Failure #2 Stack around the variable 'list' was corrupted.是指栈被破坏吗,应该如何修改?看名字是list的问题,但我看了半天也找不出哪里的问题,为什么不会影响这个程序的运行,我百度Google了半天没找到。
还有一个:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
程序代码:
#include <stdio.h>

void input (struct student *,int *);
void output (struct student);
struct student
{
    char name[20];
    int age;
    int score;
    char ach;
    int stdid;
};

int main(void)
{
    struct student list[1];
    int stdidall = 0;

    input(&list[0],&stdidall);
    printf("Complete\n");
    input(&list[1],&stdidall);
    printf("Complete\n");

    printf("--------------------------\n");
    output(list[0]);
    output(list[1]);
    return 0;
}

void input (struct student * temp , int * tempall)
{
    printf("Enter Student Name:");
    scanf("%s",temp->name);
    printf("Enter Student Age:");
    scanf("%d",&temp->age);
    printf("Enter Student Score:");
    scanf("%d",&temp->score);

    if (90 <= temp->score)
        temp->ach = 'A';
    else if (70 <= temp->score)
        temp->ach = 'B';
    else if (60<= temp->score)
        temp->ach = 'C';
    else if (50<= temp->score)
        temp->ach = 'D';
    else
        temp->ach = 'F';
    *tempall = *tempall + 1;
    temp->stdid = *tempall;

    return;
}

void output (struct student temp)
{
    printf("Name:%s\nAge:%d\nScore:%d\nAchievement:%c\nNo.:%d\n", temp.name , temp.age , temp.score , temp.ach , temp.stdid);
    return;
}

搜索更多相关主题的帖子: 如何 影响 function declared properly 
2011-10-15 17:11
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
得分:0 
这这这.....我.....貌似我一直想着数组从0开始.....

不过这里我定义成1的话不就只有1个元素了吗

那 input(&list[1],&stdidall);又是怎么执行的呢?
2011-10-15 17:27
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
得分:0 
感谢!
2011-10-15 18:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-352537-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.016508 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved