C中的isatty()有什么用? [英] What is isatty() in C for?
本文介绍了C中的isatty()有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我c中isatty()的参数是什么. 我有以下代码,但我不明白第一个输出的三个数字将是1,而所有其余的是0.
Hi can anyone tell me what is the paramter of isatty() in c. I have following code, but I don't understand the first output three number would be 1 and all the left is 0.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
for(int i=0;i<100;i++){
int t=isatty(i);
printf("%d",t);
}
return 0;
}
推荐答案
快速浏览手册页会发现:
A quick look at your man pages would reveal:
int isatty(int fildes);
DESCRIPTION
The isatty() function tests whether fildes, an open file
descriptor, is associated with a terminal device.
进一步的研究将使您发现,按照惯例,文件描述符0、1和2(即STDIN_FILENO,STDOUT_FILENO和STDERR_FILENO)被设置为在程序从终端运行时指向终端.
Further investigation would lead you to the discovery that file descriptors 0, 1 and 2 (aka STDIN_FILENO, STDOUT_FILENO and STDERR_FILENO) are by convention set up to point to your terminal when your program is running from a terminal.
这篇关于C中的isatty()有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文