-2
我想寫這個簡單的程序,它在一個scanf函數中讀取多個變量,但輸入輸入後會引發異常?訪問衝突寫入位置0x00D00000
編輯:我最初使用scanf,但它會導致錯誤,說它可能是不安全的。
拋出異常:
異常在0x52DAB87C(ucrtbased.dll)中的Program.exe拋出:0000005:訪問衝突寫入位置0x00D00000
#include <stdio.h>
#include <stdlib.h>
void main()
{
char name[20];
int age;
char gender;
float income;
printf("Enter <name> <age> <gender> <income> :");
scanf_s("%s %d %c %f", &name, &age, &gender, &income);
printf("Name : %s", name);
printf("Age : %d", age);
printf("Gender : %c", gender);
printf("Income : %.2f", income);
system("pause");
}
爲什麼使用C++標籤? – 2017-06-14 13:08:41
不確定是否修正了它:'&name' =>'name' –
'scanf_s(「%s%d%c%f」,&name,&age,&gender,&income);' - >'scanf_s(「%19s% d%c%f「,name,20,&age,&gender,1,&income);' – BLUEPIXY