C read file line by line

前端 未结 17 2198
后悔当初
后悔当初 2020-11-22 03:45

I wrote this function to read a line from a file:

const char *readLine(FILE *file) {

    if (file == NULL) {
        printf(\"Error: file pointer is null.\"         


        
17条回答
  •  鱼传尺愫
    2020-11-22 04:20

    FILE* filePointer;
    int bufferLength = 255;
    char buffer[bufferLength];
    
    filePointer = fopen("file.txt", "r");
    
    while(fgets(buffer, bufferLength, filePointer)) {
        printf("%s\n", buffer);
    }
    
    fclose(filePointer);
    

提交回复
热议问题