-1
我不斷收到的讀訪問衝突每當我嘗試運行此代碼:嘗試將scanf_s寫入struct *時讀取訪問衝突寫入位置?
#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做的,但我不知道是什麼改變。謝謝
也許你應該[找到一個很好的初學者兩本書(http://stackoverflow.com/questions/562303/the-definitive -c-book-guide-and-list),因爲你沒有將正確的參數傳遞給'scanf'。 –
'scanf_s(「%s%f%f」,進入 - >名稱,進入 - >速率,進入 - > hoursWorked);' - >'scanf_s(「%s%f%f」 sizeof(進入 - >名稱),進入 - >速度,並進入 - > hoursWorked);','printf(「%c%f%f」,workers [i] .name,workers [i] .rate,workers [i ] .hoursWorked);' - >'printf(「%s%f%f」,workers [i] .name,workers [i] .rate,workers [i] .hoursWorked);' – BLUEPIXY
'scanf_s(「 s「...」需要2個以下參數。 – chux