I know everyone's been using Byte[512] or something like that but I really wanna try using malloc.
I create a pointer "block" point it to an empty memory with 512 spaces. Then I read from raw and put all those 0's and 1's in my 512 byte and so I use block[??] to compare the bytes. Am i doing something wrong??? like every time fread was implimented block was set to 0. kinda confused
#include<stdio.h> #include<cs50.h> #include<stdlib.h> int main(int argc, char* argv[]) { int num = 0; FILE* inpt = fopen("card.raw", "r"); int* block = malloc(512); char* title = malloc(8); sprintf(title,"%d%d%d.jpg",(num-num%100-num%10)/100,(num%100-num%10)/10,num%10); FILE* out = fopen(title,"w"); while(fread(block,sizeof(block),1,inpt) == 1) { if(block[0]==0xff && block[1] == 0xd8 && block[2] == 0xff && block[3] >= 0xe0 && block[3] <= 0xef) { sprintf(title,"%d%d%d.jpg",(num-num%100-num%10)/100,(num%100-num%10)/10,num%10); fclose(out); out = fopen(title,"w"); num++; } if(num > 0) fwrite(block,sizeof(block),1,out); } fclose(out); fclose(inpt); free(block); free(title); }