【发布时间】:2019-05-17 06:26:26
【问题描述】:
在 Visual Studio 2017 中,我在使用 scan_s()、printl_s() 和 char 编写简单的输入和输出应用程序时遇到问题。请查看 2 个应用程序,请帮助解释我使用 scan_s()、printl_s() 和 char 时出现的问题。
这段代码没问题:
#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
这个错了:
#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.
【问题讨论】:
-
请添加更多代码供我们查看
-
请发布您的代码和输出文本而不是图像,请参阅How to Ask。