For some reason my C program closes immediately after outputting "Enter a letter (D/E/F): "
I would like to be able to store 3 characters in the letters[] array so that I can print them later on.
I use Visual Studio 2017 and the program has no errors. It just seems to skips everything after printf("Enter a letter (D/E/F): ");
.
I think the problem has to do with scanf_s, but I don't exactly know what the problem is or how to fix it. Here's my program:
#include <stdio.h>
int main(void)
{
char letters[3];
char ch;
printf("Enter a letter (A/B/C): ");
scanf_s(" %c", &ch);
letters[0] = ch;
printf("Enter a letter (D/E/F): ");
scanf_s(" %c", &ch);
letters[1] = ch;
printf("Enter a letter (G/H/I): ");
scanf_s(" %c", &ch);
letters[2] = ch;
printf("You entered %c, %c, and %c.", letters[0], letters[1], letters[2]);
getchar(); getchar(); // PAUSE
return 0;
}
Please help.