Read all content

    0

    3

    Giovanny Gongora

    Codiga's C Recipes

    Read all content from a text file

    #include <stdio.h>
    
    int readAllContent() {
      FILE* fp = fopen("abc.txt", "r");
      fseek(fp, 0, SEEK_END);
      long size = ftell(fp);
      fseek(fp, 0, SEEK_SET);
      char* fcontent = (char*)malloc(size);
      fread(fcontent, 1, size, fp);
      fclose(fp);
      printf("%s\n", fcontent);
      return 0;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.