源码:
// charcode.cpp : 定义控制台应用程序的入口点。
//
/* charcode.c 显示一个字符的编码值 */
#include "stdafx.h"//建立项目时系统自动加的,不知道有什么用
#include <stdio.h>
#include <Windows.h>//系统头文件,包含system()函数
int main(void)
{
char ch;
printf("Please enter a character \n");
scanf_s("%c", &ch);//用scanf();编译出错
printf("The code for %c is %d.\n", ch, ch);
system("pause");//暂停函数
/*
fflush(stdin);
getchar();*///没什么用,程序还是停不下来
//scanf_s("go on");//程序停不下来
return 0;
}
解决以下问题:
1.为什么使用scanf();函数编译出错?
2.为什么无法使用getchar();或者scanf_s();将程序停下来(后来使用了system(“pause”);使程序停下来)
3.输出结果如下图,为什么输出是错误的?
附加信息:
1.使用的编译环境为Visual Studio 2015 中文专业版 c++ Win32
2.使用scanf();函数时编译错误的的信息:
charcode.cpp
f:\学校\c primer plus\3\example\3.5\charcode\charcode\charcode.cpp(14): error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\windows kits\10\include\10.0.10150.0\ucrt\stdio.h(1270): note: 参见“scanf”的声明
项目 : error (null) : Build errors occurred.
3.在scanf_s("%c", &ch);处设置断点后,自动窗口如下:
// charcode.cpp : 定义控制台应用程序的入口点。
//
/* charcode.c 显示一个字符的编码值 */
#include "stdafx.h"//建立项目时系统自动加的,不知道有什么用
#include <stdio.h>
#include <Windows.h>//系统头文件,包含system()函数
int main(void)
{
char ch;
printf("Please enter a character \n");
scanf_s("%c", &ch);//用scanf();编译出错
printf("The code for %c is %d.\n", ch, ch);
system("pause");//暂停函数
/*
fflush(stdin);
getchar();*///没什么用,程序还是停不下来
//scanf_s("go on");//程序停不下来
return 0;
}
解决以下问题:
1.为什么使用scanf();函数编译出错?
2.为什么无法使用getchar();或者scanf_s();将程序停下来(后来使用了system(“pause”);使程序停下来)
3.输出结果如下图,为什么输出是错误的?
附加信息:
1.使用的编译环境为Visual Studio 2015 中文专业版 c++ Win32
2.使用scanf();函数时编译错误的的信息:
charcode.cpp
f:\学校\c primer plus\3\example\3.5\charcode\charcode\charcode.cpp(14): error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\windows kits\10\include\10.0.10150.0\ucrt\stdio.h(1270): note: 参见“scanf”的声明
项目 : error (null) : Build errors occurred.
3.在scanf_s("%c", &ch);处设置断点后,自动窗口如下: