GNU >> C/C++

read file line by line


main.c

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

int main(int argc, char **argv)
{
    FILE *f = NULL;
    char buf[255] = {0};

    f = fopen("test.txt", "r");
    while (fgets(buf, sizeof(buf), f)) {
        printf("%s\n", buf);
    }
    fclose(f);
    return 0;
}


返回上一頁