1.系统使用差异
-- getch()函数不是C标准函数,仅在MS-DOS下可以使用,需要包含#include <conio.h> 头文件。
-- getchar()函数是C标准函数,但是在Linux和Windows的系统下均可以使用,需要包含 #include <stdio.h>
编译之后会显示如下的警告:
3.输入的不同:
-- getch()函数不是C标准函数,仅在MS-DOS下可以使用,需要包含#include <conio.h> 头文件。
-- getchar()函数是C标准函数,但是在Linux和Windows的系统下均可以使用,需要包含 #include <stdio.h>
2.在使用VC10的编译器时使用如下代码
#include <stdio.h>
#include <conio.h>
int main(void)
{
char ch = 0;
int i=0;
for(i=0;i<10;i++)
{
ch = getch();
printf("%c\n",ch);
}
return 0;
}
编译之后会显示如下的警告:
E:\Program-Practice\Qt-Program\test\main.c:10: 警告:C4996: 'getch': The POSIX name for this item is deprecated.
Instead, use the ISO C++ conformant name: _getch. See online help for details.
ch = getch(); ----> ch = _getch();
就没有任何警告
undefined reference to `getch'
3.输入的不同:
当 ch = getch() ; 时,不会再中断中显示数输入的字符;
当 ch = getchar() ; 时 ,会显示出输入的字符,当接收到回车字符时,会把缓冲区中的数据送到内存中去,当输入的字符过多时,就会舍弃溢出的字符;