浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

       #define _GNU_SOURCE
       #include <stdio.h>
       #include <stdlib.h>

       int main(void)
       {
            FILE * fp;
            char * line = NULL;
            size_t len = 0;
            ssize_t read;
            fp = fopen("/etc/motd", "r");
            if (fp == NULL)
                 exit(EXIT_FAILURE);
            while ((read = getline(&line, &len, fp)) != -1) {
                 printf("Retrieved line of length %zu :\n", read);
                 printf("%s", line);
            }
            if (line)
                 free(line);
            return EXIT_SUCCESS;
       }

CONFORMING TO
       Both getline() and getdelim() are GNU extensions.  They are available since libc 4.6.27.

SEE ALSO
       read(2), fgets(3), fopen(3), fread(3), gets(3), scanf(3)

posted on 2013-03-11 16:00  lexus  阅读(238)  评论(0编辑  收藏  举报