made examples/demos for vectors && files && lists | also fixed a bug with the vector and list size and popping, explained in the adjacent comment
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#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);
|
||||
|
||||
// TODO -> writing, clearing
|
||||
|
||||
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\n");
|
||||
fileCleanup(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
this !1@#%
|
||||
is a big
|
||||
mega such large
|
||||
|
||||
test
|
||||
and
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <odweta/list.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("creating a list using 'listInit()' (returns a list_t*)\n");
|
||||
list_t* l = listInit();
|
||||
|
||||
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");
|
||||
listPush(l, INT, &(int){123});
|
||||
listPrint(l);
|
||||
|
||||
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");
|
||||
int poppedValue = *((int *)listPop(l));
|
||||
printf("popped: %d\n", poppedValue);
|
||||
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");
|
||||
listCleanup(l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <odweta/vector.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("creating a vector using 'vectorInit(<type>)' (returns a vector_t*)\npossible type are: INT, FLOAT, CHAR, VECTOR (LIST in the future)\n");
|
||||
vector_t* v = vectorInit(INT);
|
||||
|
||||
printf("pushing an integer value into the vector\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})\n->'vectorPush(vector_t*, &(int){123})'\n");
|
||||
vectorPush(v, &(int){123});
|
||||
vectorPrint(v);
|
||||
|
||||
printf("popping the last value of the vector; in this case, it is an integer, so you type: 'int poppedValue = *((int *)vectorPop(vector_t*))'\n");
|
||||
int poppedValue = *((int *)vectorPop(v));
|
||||
printf("popped: %d\n", poppedValue);
|
||||
vectorPrint(v);
|
||||
|
||||
printf("if you are finished working with the vector BEFORE the immediate end of the program, run 'vectorCleanup(vector_t*)', otherwise it is not strictly necessary\n");
|
||||
vectorCleanup(v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user