In Visual studio 2017, I have a problem with scan_s()
, printl_s()
and char
to code simple input and output app. Please review 2 app and please help to explain help me what is the issue when I used scan_s()
, printl_s()
and char
.
This code is ok:
#include <stdio.h>
int main() {
char name[30];
printf("Enter name: ");
gets(name); // enter string
printf("Name: ");
puts(name); // display string
_getch();
}
Enter name: Dung_cute
Name: Dung_cute
This one is wrong:
#include <stdio.h>
int main() {
char name[20];
printf_s("Enter name: ");
scanf_s("%c", name); // enter string
printf("Your name is: %s.", name);
_getch();
}
Enter name: Dung_cute
Your name is: D?????aietnauie'ai.