手机
当前位置:查字典教程网 >编程开发 >C语言 >详解C语言中的ttyname()函数和isatty()函数的用法
详解C语言中的ttyname()函数和isatty()函数的用法
摘要:C语言ttyname()函数:返回一终端机名称头文件:#include定义函数:char*ttyname(intdesc);函数说明:如果参...

C语言ttyname()函数:返回一终端机名称

头文件:

#include <unistd.h>

定义函数:

char * ttyname(int desc);

函数说明:如果参数desc 所代表的文件描述词为一终端机, 则会将此终端机名称由一字符串指针返回, 否则返回NULL.

返回值:如果成功则返回指向终端机名称的字符串指针, 有错误情况发生时则返回NULL.

范例

#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> main() { int fd; char * file = "/dev/tty"; fd = open (fiel, O_RDONLY); printf("%s", file); if(isatty(fd)) { printf("is a tty. n"); printf("ttyname = %s n", ttyname(fd)); } else printf(" is not a ttyn"); close(fd); }

执行:

/dev/tty is a tty ttyname = /dev/tty

C语言isatty()函数:判断文件描述词是否是为终端机

头文件:

#include <unistd.h>

定义函数:

int isatty(int desc);

函数说明:如果参数 desc 所代表的文件描述词为一终端机则返回1, 否则返回0.

返回值:如果文件为终端机则返回1, 否则返回0.

【详解C语言中的ttyname()函数和isatty()函数的用法】相关文章:

生成随机数rand函数的用法详解

getdate()函数的用法实例

linux下access函数的用法介绍

C++中函数模板的用法详细解析

使用C语言中的time函数获取系统时间

C语言中函数声明与调用问题

C语言中const,volatile,restrict的用法总结

strcat函数与strncat函数的深入分析

浅析C语言中assert的用法

解析C++中虚析构函数的作用

精品推荐
分类导航