NOTE: I had a previous thread about this, but since that post, I've attempted to come up with some solutions.
Just to show you, this is the place in my program where I got the variables for width and height from the input image file:
Code:
void read_header(FILE *new)
{
int max_color;
char P[10];
fgets(P, 10, new);
fscanf(new, "%d %d", &width, &height);
fscanf(new, "%d", &max_color);
}
PART 1: What I need to do is print out an error if the file size exceeds the 500 by 500 measurements (defined at the top as max_width and height).
PART 2: The other part is that I have to read the pixel information from the input file and store it into a 2d array. Each pixel has 3 values for red, green, and blue, but I'm not sure if this matters.
My attempt at both solutions:
Part 1:
Code:
void check_file_size /*Don't know what to put because width and height are global variables*/
{
if (width > 500 && height > 500)
{
perror("Error: File size too big.\n");
}
}
Part 2:
Code:
void store_into_array(FILE *input)
{
int array[max_width][max_height];
for (x = 0; x < width; x++)
{
for (y = height; y >=0; y--)
{
fscanf(input, "%d", &array[x][y]);
}
}
}