This commit is contained in:
Thomas Schleicher 2023-09-19 11:11:44 +02:00
parent 9d150c04c5
commit f98bb5cbaa
4 changed files with 26 additions and 7 deletions

View file

@ -3,4 +3,4 @@ project(c_net C)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
add_executable(c_net main.c matrix.c) add_executable(c_net main.c matrix.c image.c)

20
image.c
View file

@ -1,10 +1,12 @@
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "image.h" #include "image.h"
#include "matrix.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 // create file pointer for the image and label data
FILE* image_file = fopen(image_file_string, 'r'); 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 // check if the file could be opened
if(image_file == NULL || label_file == NULL) { 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) { void img_print (Img* img) {

View file

@ -5,6 +5,6 @@ typedef struct {
int image_label; int image_label;
} Image; } Image;
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);
void img_print (Img* img); void img_print (Image* image);
void img_free (Img* img); void img_free (Image* image);

5
main.c
View file

@ -1,7 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdio.h>
#include "matrix.h" #include "matrix.h"
#include <stdio.h> #include "image.h"
int main() { int main() {
Image** images = import_images("train-images.idx3-ubyte", "train-labels.idx3-ubyte", 20);
} }