每当我尝试运行此代码时,我都会收到读取访问冲突:
#include<stdio.h>
#include<stdlib.h>
int i = 0;
struct basicValues{
float rate, hoursWorked, grossPay, basePay, overtimePay, taxesPaid, netPay;
char name[15];
};
void inputValues (struct basicValues *entered)
{
printf("Please enter your name, hourly pay, and hours worked this week: ");
scanf_s("%s %f %f", entered->name, entered->rate, entered->hoursWorked);
}
void main()
{
int i = 0;
struct basicValues workers[5];
for (i = 0; i < 5; ++i)
{
inputValues(&workers[i]);
printf("%c %f %f", workers[i].name, workers[i].rate, workers[i].hoursWorked);
system("pause");
}
}
我认为它与我的结构inputValues有关,但我不知道要改变什么。感谢
答案 0 :(得分:0)
你应该添加&amp;在原始值类型之前,因为scanf需要变量的地址。喜欢这个
&entered->rate, &entered->hoursWorked
打印字符串时也使用%s
,而不是%c