为什么在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;
}
查看全部
Grin_Ryou
Grin_Ryou
2019/04/20 21:39
  • c语言
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复