read apue

编程技术  /  houtizong 发布于 2年前   154
准备所有的类都去掉apue.h就niuB了,fig1.4开始
ok
用vim解决,ctags -R -f systag /usr/include/ /mydir
把systag加入~/.vimrc
vim编辑的时候control+]跳到找不到了定义就行了

在P O S I X . 1应用程序中,幻数0、1、2应被代换成符号常数S T D I N F I L E N O、S T D O U T F I L E N O和S T D E R R F I L E N O。这些常数都定义在头文件< u n i s t d . h >中。
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#define BUFFSIZE    4096intmain(void){    int     n;    char    buf[BUFFSIZE];    while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)        if (write(STDOUT_FILENO, buf, n) != n)            printf("write error");    if (n < 0)        printf("read error");    exit(0);}


fcntl.h与unistd.h
http://baike.baidu.com/view/3522799.htm

----------seek-------
#include <stdio.h>#include <unistd.h>#include <stdlib.h>intmain(void){    if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1)        printf("cannot seek\n");    else        printf("seek OK\n");    exit(0);}

[root@red54apple c]# gcc fig3_11.c
[root@red54apple c]# ./a.out < epoll-test.c
,不要测试它是否小于0,而要测试它是否等于-1。
--------------getopt----
函数说明 getopt()用来分析命令行参数。参数argc和argv是由main()传递的参数个数和内容。参数 optstring为选项字符串, 告知 getopt()可以处理哪个选项以及哪个选项需要参数,如果选项字符串里的字母后接着冒号“:”,则表示还有相关的参数,全域变量optarg 即会指向此额外参数。如果在处理期间遇到了不符合optstring指定的其他选项getopt()将显示一个错误消息,并将全域变量optopt设为“?”字符,如果不希望getopt()印出错信息,则只要将全域变量opterr设为0即可
#include <unistd.h>#include <stdio.h>#include <stdlib.h>int main(int argc,char **argv){        int ch;        opterr = 0;        while((ch = getopt(argc,argv,"a:bcde"))!= -1)                switch(ch)                {                        case 'a':                                printf("option a:’%s’\n",optarg);                                break;                        case 'b':                                printf("option b :b\n");                                break;                        default:                                printf("other option :%c\n",ch);                }        printf("optopt +%c\n",optopt);}

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客