Answers for "C read entire file"

1

read entire file c

char *read_file_content_path(char const *filepath)
{
    FILE *file = fopen(filepath, "r");
    int file_size;
    char *text;

    fseek(file, 0L, SEEK_END);
    file_size = ftell(file);
    rewind(file);
    text = malloc(file_size + 1);
    fread(text, 1, file_size, file);
    text[file_size] = '';
    fclose(file);
    return text;
}
Posted by: Guest on June-12-2021

Browse Popular Code Answers by Language