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:
@@ -1,41 +1,21 @@
|
||||
#include <odweta/list.h>
|
||||
#include <odweta/vector.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
list_t *l = listInit();
|
||||
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);
|
||||
|
||||
vector_t *to_be_pushed_vec = vectorInit(INT);
|
||||
vectorPush(to_be_pushed_vec, &(int){1620});
|
||||
listPush(l, VECTOR, (vector_t *)to_be_pushed_vec);
|
||||
listPush(l, FLOAT, &(float){3.14});
|
||||
listPush(l, CHAR, &(char){'x'});
|
||||
listPush(l, INT, &(int){123});
|
||||
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);
|
||||
|
||||
listPrint(l);
|
||||
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("popping for the 1st time\n");
|
||||
int popped = *((int *)listPop(l));
|
||||
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);
|
||||
|
||||
printf("popped: %d\n", popped);
|
||||
|
||||
listPrint(l);
|
||||
|
||||
printf("popping for the 2nd time\n");
|
||||
char cpopped = *((char *)listPop(l));
|
||||
|
||||
printf("popped: '%c'\n", cpopped);
|
||||
|
||||
listPrint(l);
|
||||
|
||||
printf("popping for the 3rd time\n");
|
||||
float fpopped = *((float *)listPop(l));
|
||||
|
||||
printf("popped: %f\n", fpopped);
|
||||
|
||||
listPrint(l);
|
||||
|
||||
listCleanup(l);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user