PSET 4 is really taking me for a wild ride that I am not enjoying whatsoever.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
int num = 0;
typedef uint8_t BYTE;
char *jpgName = " ";
int main(int argc, char *argv[])
{
// Set command line argument I want to accept
char *verify = "card.raw";
// Compare acceptable command line argument with inputted argument. Only provide error if incorrect.
if(strcmp(argv[1], verify) == 0 && argc == 2)
{
//If argument is accepted give yourself a pat on the back
printf("Good Job.\n");
}
else
{
printf("Try again Bozo\n"); //try again
return 1;
}
char *infile = argv[1]; //Change the name of argv[1] to *infile for some reason?
BYTE buffer[512]; //Create my 512 byte array
FILE *f=fopen(infile, "r");//open card.raw file
fread(&buffer, sizeof(BYTE), 512, f);//read my card.raw file into buffer
//Make sure that the file is a JPEG.
if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
//Create the name of my jpgfile.
sprintf(jpgName, "%03i.jpg", num);
//Increment it
num++;
// Open a new file called *img with the jpgName
FILE *img = fopen(jpgName, "w");
// Write to the jpgName file
fwrite(&buffer ,sizeof(BYTE), number ,*img)
}
}
I don't really have any way to check if what I am doing is in any way correct before I actually finish the PSET and I feel stuck at this point. I have a suspicion that fread(&buffer, sizeof(BYTE), 512, f);
should actually be fread(&buffer, sizeof(buffer), 1, f);
but I am not sure. Is the size of the element the entire array and there is only one of them? Or is the size of each element one byte and there are 512 of them?
How does the fwrite program know when to terminate if the image is larger than one single 512 byte array? I've watched the video multiple times now and don't know how to continue.
This PSET seems a lot trickier than the previous ones.