#include
int main()
{
char name[256];
float height, weight;
printf("请输入您的姓名:");
scanf_s("%s", name);
//gets(name);
printf("请输入您的身高(cm):");
scanf_s(" %f", &height);
printf("请输入您的体重(kg):");
scanf_s(" %f", &weight);
printf("========== 正在为您转换 ==========\n");
height = height / 2.54; // 厘米转换为英寸
weight = weight / 0.453; // 公斤转换为磅
printf("%s的身高是%.2f(in),体重是%.2f(lb)。\n", name, height, weight);
return 0;
}
在输入姓名回车后就出现错误了.
亲 ,少个&?
scanf_s("%s",&name);
scanf_s需要3个参数:格式、参数、大小
Unlike scanf and wscanf,scanf_s and
wscanf_s require the buffer size to be specified for all input parameters of typec,
C, s, S, or string control sets that are enclosed in[]. The buffer size in characters is passed as an additional parameter immediately following the pointer to the buffer or variable.