made a better list demo
This commit is contained in:
@@ -1,24 +1,31 @@
|
|||||||
#include <odweta/file.h>
|
#include <odweta/list.h>
|
||||||
|
#include <odweta/vector.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("creating a file using 'fileInit(<filename>)' (returns a file_t*)\n");
|
printf("creating a list using 'listInit()' (returns a list_t*)\n");
|
||||||
file_t* f = fileInit("test.txt");
|
list_t* l = listInit();
|
||||||
|
|
||||||
printf("printing the file contents\n\n");
|
printf("pushing an integer value into the list\nnote the kind of unusual way of passing the number argument: if you want to pass an expression (e.g. the value '1' or '4*4'), something not stored in a variable, you follow this syntax - &(type){value} (e.g. &(int){1 + 1})\nalso, the type of the variable must be given as the second argument to the function\n->'listPush(list_t*, INT, &(int){123})'\n");
|
||||||
filePrint(f);
|
listPush(l, INT, &(int){123});
|
||||||
|
listPrint(l);
|
||||||
|
|
||||||
printf("\nconvering the file contents into a string (char*)\n");
|
printf("popping the last value of the list; in this case, it is an integer, so you type: 'int poppedValue = *((int *)listPop(list_t*))'\n");
|
||||||
char* string = fileToString(f);
|
int poppedValue = *((int *)listPop(l));
|
||||||
printf("\"%s\"\n", string);
|
printf("popped: %d\n", poppedValue);
|
||||||
|
listPrint(l);
|
||||||
|
|
||||||
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");
|
printf("more examples with diferrent types\nnote that the vector_t* is a pointer, so there is no need to write the special syntax!\n");
|
||||||
fileWrite(f, "'this will not end with a \"\\n\"' ");
|
listPush(l, FLOAT, &(float){3.14});
|
||||||
fileWriteln(f, "this line was appended");
|
listPush(l, CHAR, &(char){'x'});
|
||||||
filePrint(f);
|
vector_t* int_vec = vectorInit(INT);
|
||||||
|
vectorPush(int_vec, &(int){456});
|
||||||
|
listPush(l, VECTOR, int_vec);
|
||||||
|
|
||||||
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");
|
listPrint(l);
|
||||||
fileCleanup(f);
|
|
||||||
|
printf("if you are finished working with the list BEFORE the immediate end of the program, run 'listCleanup(list_t*)', otherwise it is not strictly necessary\n");
|
||||||
|
listCleanup(l);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <odweta/list.h>
|
#include <odweta/list.h>
|
||||||
|
#include <odweta/vector.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@@ -14,6 +15,15 @@ int main() {
|
|||||||
printf("popped: %d\n", poppedValue);
|
printf("popped: %d\n", poppedValue);
|
||||||
listPrint(l);
|
listPrint(l);
|
||||||
|
|
||||||
|
printf("more examples with diferrent types\nnote that the vector_t* is a pointer, so there is no need to write the special syntax!\n");
|
||||||
|
listPush(l, FLOAT, &(float){3.14});
|
||||||
|
listPush(l, CHAR, &(char){'x'});
|
||||||
|
vector_t* int_vec = vectorInit(INT);
|
||||||
|
vectorPush(int_vec, &(int){456});
|
||||||
|
listPush(l, VECTOR, int_vec);
|
||||||
|
|
||||||
|
listPrint(l);
|
||||||
|
|
||||||
printf("if you are finished working with the list BEFORE the immediate end of the program, run 'listCleanup(list_t*)', otherwise it is not strictly necessary\n");
|
printf("if you are finished working with the list BEFORE the immediate end of the program, run 'listCleanup(list_t*)', otherwise it is not strictly necessary\n");
|
||||||
listCleanup(l);
|
listCleanup(l);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user