initial commit

This commit is contained in:
Odweta
2023-12-07 20:03:18 +01:00
commit 7fb1267224
8 changed files with 722 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
#ifndef FILE_H
#define FILE_H
#include <odweta/vector.h>
#include <stdio.h>
typedef struct {
FILE* descriptor; // the file descriptor
int length; // line count
vector_t* lines; // 2d array of chars
} file_t;
file_t* fileInit(char* path, char* mode); // initialization function
// TODO: when there is not a '\n' at the end of a file, the last line is not loaded :(
void fileCleanup(file_t* f); // just to be memory safe...
int fileCountLines(file_t* f); //
void filePrint(file_t* f);
char* fileToString(file_t* f);
#endif
+54
View File
@@ -0,0 +1,54 @@
#ifndef VECTOR_H
#define VECTOR_H
typedef long unsigned int size_t;
typedef enum {
INT,
FLOAT,
CHAR,
VECTOR // allows for multi-dimensional arrays
} dataType_e;
typedef struct {
dataType_e type;
size_t size;
size_t capacity;
size_t elementSize;
void* data;
} vector_t;
vector_t*
vectorInit(dataType_e dataType); // size gets determined by the dataType and the capacity starts at 1 and x1.5 every time the vector gets filled up
void
vectorReset(vector_t* v); // sets the vector to its original state
void*
vectorPop(vector_t* v); // remove one value from the end of the vector and return it
void
vectorPush(vector_t* v, void* element); // push one value at the end of the vector
void
vectorCleanup(vector_t* v); // freeing pointers
void
vectorPrint(vector_t* v); // shows the vector
void
vectorPrintAsString(vector_t* v); // show the vector as a string if the v->type is CHAR
void
vectorInsertAt(vector_t* v, int index, void* element); // inserts an element 'element' at index 'index'
void
vectorSetAt(vector_t* v, int index, void* element); // set an element's value at a given index
char*
vectorToString(vector_t* v); // convert the vector into a regular string
void*
vectorGetAt(vector_t* v, int index); // get an element at the given index
#endif