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
+39 -1
+39 -1
View File
@@ -7,16 +7,54 @@
#define FILE_HEADER_STRING "__info2_image_file_format__"
// 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
GrayScaleImageSeries *readImages(const char *path)
{
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;
}
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
void clearSeries(GrayScaleImageSeries *series)
{
}
}