i decided to create my own file, or file format; or however you wanna call it. its called DCT or Document. i didnt have a specific idea for what kind of file to make since i treated this as just a fun little side project. All you do is store text. its not efficient nor remotely useful for real world purposes, but as i said.... its just a fun side project.
personally i think the api for this is pretty clean, here a little demo:
int main()
{
// demonstrate failure
create_dct_file("fail1");
create_dct_file("fail2.weird");
// creates a valid dct (document) file
create_dct_file("demo.dct");
// read header out of file
struct dct_header hd = read_dct_file_header("demo.dct");
hd.dct[0] = 'x'; // manipulate & invalidate for next test case
write_dct_file_header("demo.dct", &hd); // will fail because it validates header internally
// log
printf("\n"); // Seperator to Seperate from Earlier Functions Error Case Testings
printf("sizeof(struct dct_header): %llu\n", sizeof(struct dct_header));
printf("Old Character Count: %hu\n", hd.char_count);
printf("Old File Size: %llu\n", hd.file_size);
// write text into file
char txt1[] = "Hello, DCT. ";
char txt2[] = "DCT is the short version for \"Document\"";
write_dct_text("demo.dct", txt1, sizeof(txt1) - 1);
write_dct_text("demo.dct", txt2, sizeof(txt2) - 1);
hd = read_dct_file_header("demo.dct"); // read updated header (write_dct_text updates char count and size internally)
// log
printf("New Character Count: %hu\n", hd.char_count);
printf("New File Size: %llu\n\n", hd.file_size);
print_file_bytes("demo.dct");
return 0;
}