Skip to content

Instantly share code, notes, and snippets.

@Einlander
Last active December 12, 2015 08:24
Show Gist options
  • Select an option

  • Save Einlander/c6fdf2560486315921c2 to your computer and use it in GitHub Desktop.

Select an option

Save Einlander/c6fdf2560486315921c2 to your computer and use it in GitHub Desktop.
Read entire text file at once
//load file to mem
import "ecere"
void file_read(const String filename)
{
// with code from http://rosettacode.org/wiki/Read_entire_file#C
char *buffer;
File FileHandler = FileOpen(filename, read);
if (FileHandler)
{
buffer = malloc(FileHandler.GetSize());
if (buffer != null)
{
FileHandler.Read(buffer,FileHandler.GetSize(),1);
FileHandler.Close();
PrintLn(buffer);
}
}else{
PrintLn("File not loaded");
}
PrintLn("Done");
}
class HelloApp : Application
{
void Main()
{
file_read("vert.vert");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment