「已注销」 2022-08-01 16:04 采纳率: 87.5%
浏览 39
已结题

这个程序为啥运行后直接就结束了

#include<stdio.h>
#include<string.h>
#define DENSITY 62.4
int main(void)
{
float weight, volume;
int size, letters;
char name[40];
printf("Hi! What's your frist name?\n");
scanf_s("%s", name);
printf("%s,Whats 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, weight);
printf("Also,your frist name has %d letters,\n", letters);
printf("and we have %d bytes to store it.\n", size);
return 0;

}

  • 写回答

2条回答 默认 最新

  • qzjhjxj 2022-08-01 16:20
    关注

    scanf_s("%s", name); 修改为: scanf_s("%s", name, 40);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月9日
  • 已采纳回答 8月1日
  • 创建了问题 8月1日