问题栏

用户名:xuxiang

悬赏金:40鼠币

为什么在c语言使用数组时会发生访问冲突?

我想请问一下这里为什么会在scanf_s("%s", name);处抛出异常,调整了堆栈保留大小也不行,谢谢

#include <stdio.h>
#include <string.h>
#define density 62.4
int main()
{
float weight, volume ;
int size, letters;
char 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 %d bytes to store it.\n", size);
getchar();
return 0;
}

发布时间:2019-04-22
解答栏
  • 用户名:MASHEN

    scanf_s("%s", name);
    ->
    scanf_s("%s", name, 40); //需要缓冲区长度的参数

    发布时间:2019-04-22



撰写答案
请登录后再回答