Giúp so sánh 2 code

cả 2 đoạn đều mô tả việc đọc dữ liệu từ file rồi in ra màn hình. giúp em kiểm tra xem tại sao đoạn 1 chạy sai mà đoạn 2 chạy đúng vậy. em cảm ơn

đoạn 1:

#include <stdio.h>
#include <stdlib.h>
int main(){
    FILE *taptin=NULL;
    taptin=fopen("C:\\User\\pc\\Desktop\\thuvien.txt", "r");
    char **s=(char **)malloc(4*sizeof(char *));
    for (int i = 0; i < 4; i++)
    {
        *(s+i)=(char *)malloc(256*sizeof(char));
    }
    for (int i = 0; i < 4; i++)
    {
        fgets(*(s+i), 256, taptin);
        printf(*(s+i));
        
    }
    fclose(taptin);
    return 0;
}

đoạn 2:

#include <stdio.h>
#include <stdlib.h>
int main(){
    FILE *taptin=NULL;
    taptin=fopen("C:\\Users\\pc\\Desktop\\thuvien.txt","r");
    char **s=(char **)malloc(4*sizeof(char *));
    for (int i = 0; i < 4; i++)
    {
        *(s+i)=(char *)malloc(256*sizeof(char));
    }
    for (int i = 0; i < 4; i++)
    {
        fgets(*(s+i), 256, taptin);
        printf(*(s+i));

    }
    fclose(taptin);
    
    
    return 0;
}

:thinking: Bug này nó lặn ghê đấy

taptin=fopen(“C:\User\pc\Desktop\thuvien.txt”, “r”);

taptin=fopen(“C:\Users\pc\Desktop\thuvien.txt”,“r”);

8 Likes
1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?