diff --git a/.theia/tasks.json b/.theia/tasks.json new file mode 100644 index 0000000..b2a68a7 --- /dev/null +++ b/.theia/tasks.json @@ -0,0 +1,12 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "runBuild", + "type": "shell", + "command": "./build_and_run.sh" + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f7868e..d730321 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(advanced_C_standard_library C) -set_property(GLOBAL PROPERTY C_STANDARD 11) +set_property(GLOBAL PROPERTY C_STANDARD) cmake_minimum_required(VERSION 3.9) include_directories(src) file(GLOB SOURCES "src/*.c") @@ -8,3 +8,4 @@ find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") endif() +set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) diff --git a/src/file.c b/src/file.c new file mode 100644 index 0000000..170cf84 --- /dev/null +++ b/src/file.c @@ -0,0 +1,28 @@ +#include +#include +#include +char* acl_ReadFileString(char *filePath, bool *sucess){ + FILE *fp = fopen(filePath, "rb"); + size_t lSize; + char *buffer; + if(!fp) { + *sucess = false; + return buffer; + } + fseek(fp, 0L, SEEK_END); + lSize = ftell(fp); + rewind(fp); + buffer = malloc(lSize + 1); + if(!buffer) { + fclose(fp); + *sucess = false; + return buffer; + } + size_t readReturn = fread(buffer, lSize, 1, fp); + fclose(fp); + if(readReturn != 1) { + *sucess = false; + } + *sucess = true; + return buffer; +} diff --git a/src/file.h b/src/file.h new file mode 100644 index 0000000..b098a62 --- /dev/null +++ b/src/file.h @@ -0,0 +1,5 @@ +#ifndef acl_file_h +#define acl_file_h +#include +char* acl_ReadFileString(char *filePath, bool *sucess); +#endif diff --git a/src/main.c b/src/main.c index 9d48d73..1fd749a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,11 +1,13 @@ #include #include "array.h" #include - +#include "file.h" +#include int main() { - int *int_array = acl_arraylist_create(2, sizeof (int)); - int_array[0] = 28; - int_array[1] = 20; - for(int i = 0; i < 10; ++i) acl_arraylist_append(int_array, &i); - for(int i = 0; i < 12; ++i) printf("Index: %d Value: %d\n", i, int_array[i]); + bool sucess; + char *content = acl_ReadFileString("LICENSE", &sucess); + if(sucess) { + printf("%s", content); + } + else printf("Erorror\n"); }