Starting from:

$10

standard I/O library functions

Using the standard I/O library functions (fopen(), fseek(), fread(), etc), write a C program
to transform a given picture into an up-side-down picture. In particular, your program should
reverse the image by directly reading from one file and writing to another, without the need of
a two-dimensional array.
The input image is a grayscale picture, where each pixel has a value between 0(black) and
255(white). The image is simply an nbLines × nbCols matrix of bytes, where each byte store
the gray-level of the corresponding pixel.
nbLines is the number of lines and nbCols is the number of columns.
To help you understand the structure of the binary file containing the image, here is the
function that was used to store the image in a file.
void saveImage(char **image, int nbLines, int nbCols, FILE *fd){
int i;
fputs("P5\n", fd); // just a code
fprintf(fd, "%d %d\n", nbLines, nbCols);
fputs("255\n", fd); // another code
for(i=0; i<nbLines; i++)
fwrite(image[i], nbCols, fd);
}
Notes :
• The image(the input file to your program) has to be downloaded from
http://boufama.myweb.cs.uwindsor.ca/256/assignments/Assign03/m1.pgm
• Many image reader can be used to view your images (input and output). You can, for example, use the UltraFileOpener that can be downloaded from http://www.ultrafileopener.com.

More products