这个也是C库中的函数,不过暂时没有发现有Linux系统调用中的对应功能的函数,格式化读---我还以为是输入一个"a"的话就可以读出它的ascii码来呢!结果人家就不认识了。结果不是下边是个小例子代表我学习过了这个函数:
#include <stdlib.h>
#include <stdio.h>
int main()
{
int i;
printf("Input an integer:");
if(fscanf(stdin, "%d", &i))
printf("The integer read was:%i\n",i);
return 0;
}
输出结果:
[abc@localhost gcc]$ ./a.out
Input an integer:1
The integer read was:1
[abc@localhost gcc]$ ./a.out
Input an integer:2
The integer read was:2
[abc@localhost gcc]$ ./a.out
Input an integer:a
[abc@localhost gcc]$