[新手]结束时报错-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; }