Skip to content

Instantly share code, notes, and snippets.

@alsamitech
Created July 8, 2021 16:46
Show Gist options
  • Select an option

  • Save alsamitech/1f6a0e93b4348166804b1d892340a297 to your computer and use it in GitHub Desktop.

Select an option

Save alsamitech/1f6a0e93b4348166804b1d892340a297 to your computer and use it in GitHub Desktop.
read_text_file - quickly reads a text file from disk
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