Answers for "c read whole file"

C
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] = '\0';
    fclose(file);
    return text;
}
Posted by: Guest on June-12-2021
0

c read a whole string from a file

#define  _GNU_SOURCE  //Necessary for getline to work with clang in Ubuntu
getline(&line, &len, fp);
Posted by: Guest on November-01-2020

Code answers related to "C"

Browse Popular Code Answers by Language