how do I read and print in console a jpg image using only fread?

Viewed 31

So... I was trying to implement a neural network that interprets images as numbers from 0 to 9 in C BUT I ran into the problem that I don´t know how to properly read a jpg file and insert the correct values into a vector (unsigned char v[3][etc...][etc...]). This is my code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int sizeOfString(const char *);
int clearString(char *);
int main(int argc, char *argv[]){

    //recieve the file through args
    char *fileName = NULL;
    unsigned char image[3][2000][2000];
    FILE* file;
    if(argv[1] != NULL){

        fileName = malloc(sizeOfString(argv[1]));
    }
    strcpy(fileName, argv[1]);
    file = fopen(fileName,"rb");

    int i = 0;
    
    for(int j = 0; j<2;j++){
        for(int k = 0;k<1999; k++);
    }
    while(1){

        printf("%d ",image[0][0][0]);
        i++;
    }
    
    printf("%d\n",i);
    fclose(file);
    return 0;
}


int sizeOfString(const char* string){

    int r=0;
    if(string != NULL){
        r = sizeof(string) / sizeof(string[0]);
    }

    return r;
}

int clearString(char *string){

    int i = 0;

    while(string[i] != '\0'){
        string[i] = '0';
        i++;
    }

    return 0;
}
0 Answers
Related