我是C的新手。我在Visual Studio Express Dekstop 2014版中键入以下代码,但输出在命令提示符下强制关闭。我试图添加getchar();
不是一次两次,而是三次也没有改变。我也尝试更改Project - > Properties - > Linker - > System - > Sub System - > Console(/ SUBSYSTEM:CONSOLE)中的设置,但现在输出显示为“没有调试器模式”,但是在“调试器模式”仍然输出在命令提示符下关闭。我还试图在return 0;
声明前使用system("pause");
。命令提示符不关闭的唯一方法是通过按F9键在return 0;
语句处应用断点。 在这种情况下我应该怎么做?命令提示符强制关闭
#include <string.h> // for strlen() prototype
#define DENSITY 62.4 // human density in lbs per cu ft
int main()
{
float weight, volume;
int size, letters;
char name[40]; // name is an array of 40 chars
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();
getchar();
return 0;
}
在每次调用'scanf_s'之前在提示中添加一个空格并再次检查。 – usr2564301 2014-09-26 13:10:49
创建一个可执行文件并从终端运行它。 – 2014-09-26 13:26:55
我非常喜欢_not一次,不是两次,而是三次。人们不会那么写。 – Yann 2014-09-26 13:29:50