open file and read first numbers and verification word

This commit is contained in:
DLZxaxrat committed 2026-11-12 11:15:32 +01:00
1 parent 447e77a7bf
commit 19abbadbb7
1 file changed
+38
+38
View File
@@ -7,11 +7,49 @@
#define FILE_HEADER_STRING "__info2_image_file_format__" #define FILE_HEADER_STRING "__info2_image_file_format__"
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei // TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
GrayScaleImage *readSingleImage(size_t widht, size_t height) {
}
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
GrayScaleImageSeries *readImages(const char *path) GrayScaleImageSeries *readImages(const char *path)
{ {
GrayScaleImageSeries *series = NULL; GrayScaleImageSeries *series = NULL;
unsigned short NumberOfImages;
unsigned short PictureWidth;
unsigned short PictureHeight;
char* verifyWord;
size_t bufferCount = 0;
FILE *file = fopen("mnist_test.info2", "rb"); // opening the file
bufferCount = fread(&verifyWord, 27, 1, file);
if (bufferCount != 1 || verifyWord != FILE_HEADER_STRING) {
strerror("Error: wrong file or unable to read the file!");
// return error code;
}
bufferCount = 0;
bufferCount = fread(&NumberOfImages, 2, 1, file);
if (bufferCount != 1) {
strerror("Error: failed to read number of pictures");
// return error code
}
bufferCount = 0;
bufferCount = fread(&PictureWidth, 2, 1, file);
if (bufferCount != 1) {
strerror("Error: failed to read the picture width!");
// return error code
}
bufferCount = 0;
bufferCount = fread(&PictureHeight, 2, 1, file);
if (bufferCount != 1) {
strerror("Error: failed to read the picture height!");
// return error code
}
return series; return series;
} }