0x516414cf (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 读取位置 0x00000046 时发生访问冲突

2025-02-28 19:27:53
推荐回答(1个)
回答1:

#include
#include 

struct Student
{
int age;
char sex;
char name[100];
};//此处的分号是不能省略的

void InputStudent(struct Student *);   //函数声明
void OutputStudent(struct Student *);//函数声明,这也错了,声明应该和调用定义参数类型保持一致,都是结构体指针类型

int main(void)
{
struct Student st;    //定义结构体变量  15行

InputStudent(&st);           //对结构体变量输入
OutputStudent(&st);   //对结构体变量输出

return 0;
}

void OutputStudent(struct Student  *pst)
{
printf("%d %c %s\n", pst->age, pst->sex , pst->name);//这里错了,注意输出顺序

}

void InputStudent(struct Student * pst)//pst只占用4个字节
{
(* pst).age = 22;
strcpy(pst->name,"张三");//strcpy是在 #include 里面的一个函数,未做讲解 
(* pst).sex = 'F';
}