25 lines
1.2 KiB
C
25 lines
1.2 KiB
C
#include <odweta/file.h>
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
|
printf("creating a file using 'fileInit(<filename>)' (returns a file_t*)\n");
|
|
file_t* f = fileInit("test.txt");
|
|
|
|
printf("printing the file contents\n\n");
|
|
filePrint(f);
|
|
|
|
printf("\nconvering the file contents into a string (char*)\n");
|
|
char* string = fileToString(f);
|
|
printf("\"%s\"\n", string);
|
|
|
|
printf("writing is quite simple, just call the 'fileWrite(file_t*, char*)' or 'fileWriteln(file_t*, char*)' function, where the second argument is the string you want to write into a file\nthe 'fileWriteln()' function writes the specified string AND a '\\n' after it, whereas the 'fileWrite()' function does not append the '\\n'\n");
|
|
fileWrite(f, "'this will not end with a \"\\n\"' ");
|
|
fileWriteln(f, "this line was appended");
|
|
filePrint(f);
|
|
|
|
printf("if you are finished working with the file BEFORE the immediate end of the program, run 'fileCleanup(file_t*)', otherwise it is not strictly necessary\nit will, though, append a '\\n' at the end of the file if you have not done so, making writing into files more consistent, so for this reason, I recommend you use it with every file_t*\n");
|
|
fileCleanup(f);
|
|
|
|
return 0;
|
|
}
|