Image

Imageescii wrote in Imagecprogramming

Another filthy C hack

Another filthy ( and dangerus ) C hack ( from memory )
Writing structures directly to files and reading them:

struct bleh{
char name[64];
char sausage[64];
char steak[64];
}

int main(){
FILE *file;
int num_e;
int i;

struct bleh meep[] =
{
{ "joe","yes please","yummy" },
{ "billy", "more baby","ooh yeah"},
{ "seven","7","seh-veh-nnn"}
};

num_e = sizeof(meep) / sizeof(bleh);

i = 0;

fopen("/tmp/blah",...);
fwrite(meep,1,sizeof(bleh * num_e),file);

/* and you can use the same method with fread to
read the entrys back out */

return 0;
}