按照C Primer Plus上的代码敲得,因为用的是vs2022,所以将scanf()改scanf_s(),运行后程序在输入名字后直接退出,请问如何解决
#include<stdio.h>
#include<string.h> //提供strlen()函数的原型
#define DENSITY 62.4 //人体密度(单位:磅/立方英尺)
int main(void)
{
float weight, volume;
int size, letters;
char name[40]; //name是一个可以容纳40个字符的数组
printf("Hi! What's your first name ?\n");
scanf_s("%s", name);
printf("%s,what's your weight in pounds?\n", name);
scanf_s("%f", &weight);
size = sizeof name;
letters = strlen(name);
volume = weight / DENSITY;
printf("Well,%s,your volume is %2.2f cubic feet.\n",
name, volume);
printf("Also,your first name has %d letters,\n", letters);
printf("and we have %dbytes to store it.\n", size);//store为储存的意思
return 0;
}
运行后程序在输入名字后直接退出
0x00007FF94C8B2079 (ucrtbased.dll)处(位于 2022_8_15_4_1_前导程序_演示与用户交互.exe 中)引发的异常: 0xC0000005: 写入位置 0x000000EEFBDC0000 时发生访问冲突。