Created
July 8, 2021 16:46
-
-
Save alsamitech/1f6a0e93b4348166804b1d892340a297 to your computer and use it in GitHub Desktop.
read_text_file - quickly reads a text file from disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char* read_text_file(const char* const filenm){ | |
| char* buf; | |
| long unsigned int len; | |
| FILE* const f=fopen(filenm, "r"); | |
| if(f){ | |
| fseek(f, 0, SEEK_END); | |
| len=ftell(f); | |
| fseek(f, 0, SEEK_SET); | |
| buf=(char*)malloc(len+1); | |
| if(buf) | |
| fread(buf, 1, len, f); | |
| buf[len]=0; | |
| fclose(f); | |
| }else buf=0; | |
| return buf; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment