c getline

       #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)

你可能感兴趣的:(get)