Function name : isatty
Header file : <io.h>
Function prototype : int isatty(int handle);
Function : Check the given device type
Parameter : int handle is the device file handle to be checked
Return value : Normal file returns 0, device returns -1
Replenish :
Common device names:
stdin standard input device keyboard
stdout standard output device display
stderr standard error device
stdaux auxiliary device
stdprn printer
Program example : Use this function to determine the device and ordinary files, and output prompts
#include<stdio.h>#include<io.h>#include<fcntl.h>intmain(void){intfd=fileno(stdout);//Get the file number of the standard output device if(isat ty(fd)){//Determine whether it is a device file or a normal file printf(%disdevice,fd);}else{printf(%disfile,fd);}putchar('n');close(fd);return0; }
Running results
1isdevice