From f98bb5cbaac82dcffdedaa0e066bfd2198711d34 Mon Sep 17 00:00:00 2001 From: Thomas Schleicher Date: Tue, 19 Sep 2023 11:11:44 +0200 Subject: [PATCH] Changes --- CMakeLists.txt | 2 +- image.c | 20 ++++++++++++++++++-- image.h | 6 +++--- main.c | 5 ++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5038efd..f1b596c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,4 +3,4 @@ project(c_net C) set(CMAKE_C_STANDARD 11) -add_executable(c_net main.c matrix.c) +add_executable(c_net main.c matrix.c image.c) diff --git a/image.c b/image.c index ccb485b..e0af441 100644 --- a/image.c +++ b/image.c @@ -1,10 +1,12 @@ #pragma once #include +#include + #include "image.h" #include "matrix.h" -Img** import_images(char* image_file_string, char* label_file_string, int number_of_images) { +Image** import_images(char* image_file_string, char* label_file_string, int number_of_images) { // create file pointer for the image and label data FILE* image_file = fopen(image_file_string, 'r'); @@ -12,9 +14,23 @@ Img** import_images(char* image_file_string, char* label_file_string, int number // check if the file could be opened if(image_file == NULL || label_file == NULL) { - printf("ERROR: File could not be opened! ()"); + printf("ERROR: File could not be opened! (import_images)"); } + do { + ch = fgetc(label_file); + printf("%c", ch); + + // Checking if character is not EOF. + // If it is EOF stop reading. + } while (ch != EOF); + + + // allocate memory for the storage of images +// Image** images = malloc(sizeof(Image) * number_of_images); + + fclose(image_file); + fclose(label_file); } void img_print (Img* img) { diff --git a/image.h b/image.h index ddd20d5..9bbf257 100644 --- a/image.h +++ b/image.h @@ -5,6 +5,6 @@ typedef struct { int image_label; } Image; -Img** import_images(char* image_file_string, char* label_file_string, int number_of_images); -void img_print (Img* img); -void img_free (Img* img); \ No newline at end of file +Image** import_images(char* image_file_string, char* label_file_string, int number_of_images); +void img_print (Image* image); +void img_free (Image* image); \ No newline at end of file diff --git a/main.c b/main.c index 5fdc7bf..d21096e 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,10 @@ #include +#include + #include "matrix.h" -#include +#include "image.h" int main() { + Image** images = import_images("train-images.idx3-ubyte", "train-labels.idx3-ubyte", 20); } \ No newline at end of file