Close command line

I am new to C. I typed the following code in Visual Studio Express Dekstop 2014, but the result is forcibly closed on the command line. I tried to add getchar();not once, but twice, but three times, but nothing changes. I also tried changing the settings in Project -> Properties -> Linker -> System -> Sub System -> Console (/ SUBSYSTEM: CONSOLE), but now the output is displayed in "no debug mode", but in "debug mode", still the output closes on the command line . I also tried using system("pause");before expression return 0;. The only way that the command line does not close is to use the breakpoint in the statement return 0;by pressing F9. What should I do in this situation?

#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 your first name?\n");
    scanf_s("%s", name);
    printf("%s, what 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;
}
+4
2

, " " (F5, ), ... , , , , , return 0;.

" " (CTRL + F5) Visual Studio , .

.

, .

, :

  • (, )
  • _getch() ( #include <conio.h>),
  • system("pause") , , .
  • - while (getchar() != '.');
+4

, Mac OSX . , . , getchar() -, ... \n, .

Getchar() , , scanf.

, Microsoft, , stdin. , getchar(). getchar() , , .

, , , unix-y \n, getchar() , getchar() .

+1

All Articles