gpt4 book ai didi

c - 访问c中的写入违规位置

转载 作者:行者123 更新时间:2023-11-30 21:40:45 25 4
gpt4 key购买 nike

在旨在获取员工姓名和信息的函数中存在访问写入冲突。当我通过开关打开该功能时,它会询问员工的姓名,但是当我按 Enter 键时,我会收到错误代码。

Unhandled exception at 0x6559DBE9 (msvcr120d.dll) in Assignment4.exe: 0xC0000005: Access violation writing location 0x009A6858.

我认为是原因的代码

typedef struct person
{
char emplyName[5][SIZE];
float emplyHours[5];
float emplyRate[5];
float emplyGross[5];
float emplyBase[5];
float emplyOvrt[5];
float emplyTax[5];
float emplyNet[5];
float emplyTotal[5];
}input;
void menu(void);

void editEmployees(input* emply);

void print(input* emply);

void employeeInfo(input* emply);

int main(void)
{
struct person *payroll={""};
int choice = 0;
menu();
scanf_s("%c", &choice,1);
switch (choice){
case '1':{
employeeInfo(payroll);
break;
}
case '2':{
editEmployees(payroll);
break;
}
case '3':{
print(payroll);
break;
}
case '4':{
break;
}
default:
printf("Invalid entry\n");
}
system("pause");
}




void employeeInfo(input *emply)
{
int i = 0;
for (i=0;i<5;i++) {
printf("Enter employee name.\n");
scanf_s("%s", &emply->emplyName[i]);
printf("Enter employee hours.\n");
scanf_s("%f", &emply->emplyHours[i]);
printf("Enter Hourly rate.\n");
scanf_s("%f", &emply->emplyRate[i]);
}
}

最佳答案

*emply 指针可能无效。它可以为空或指向随机位置。

关于c - 访问c中的写入违规位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com