Skip to content

Instantly share code, notes, and snippets.

@oatmealraisin
Created April 19, 2018 00:02
Show Gist options
  • Save oatmealraisin/d74ded033b4ce714e435a75560b59929 to your computer and use it in GitHub Desktop.
Save oatmealraisin/d74ded033b4ce714e435a75560b59929 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static const char *urls[] = {
"http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz",
"http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz",
"http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz",
"http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz"
};
int main() {
struct stat st = {0};
if(stat(".local/", &st) == -1) {
mkdir(".local/", 0755);
}
FILE *trainImages = fopen(".local/train-images-idx3-ubyte", "r");
if(trainImages == NULL) {
printf("Couldn't open file");
return 1;
}
int magicNumber;
int numItems;
int sizeRow;
int sizeColumn;
size_t ret = fread(&magicNumber, 4, 1, trainImages);
if(1 != ret) {
printf("Could not read the file");
fclose(trainImages);
return 1;
}
if( magicNumber != 0x00000308) {
printf("Incorrect magic number. Expected 0x00000308, got 0x%x\n", magicNumber);
fclose(trainImages);
return 1;
}
fclose(trainImages);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment