Question: My code is not working. #include #include #include bmp.h int main (int argc, char * argv[]); if (argc not_eq 3) { printf(Usage: ./whodunit infile outfile

My code is not working.

#include #include #include "bmp.h"

int main (int argc, char * argv[]);

if (argc not_eq 3) { printf("Usage: ./whodunit infile outfile "); return 1; }

char* infile = argv[1]; char* outfile = argv[2];

FILE* inptr = fopen(infile, "r"); if (inptr == (void *)0

{ printf("dosen't open %s. ", infile); return 2; }

FILE* outptr = fopen(outfile, "w"); if (outptr ==(void *)0 { fclose(inptr); fclose(stderr, "Couldn't make %s ", outfile); return 3; }

BITMAPFILEHEADER bf; fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

BITMAPINFOHEADER bi; fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);

if (bf.bfType not_eq 0x4d42 or bf.bfOffBits not_eq 54 or bi.bisize not_eq 40 or bi.biBitCount not_eq 24 or bi.bicompression not_eq 0)

{ fclose(outptr); fclose(inptr); fprintf(stderr, "Not supported file format. "); return 4;

fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr); fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);

int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i ++

for (int j = 0; j < bi.biWidth; j++)

RGBTRIPLE triple;

fread(&triple, sizeof(RGBTRIPLE), i, inptr);

if (triple.rgbtBlue == 0x00 and triple.rgbtGreen == 0x00 and triple.rgbt == 0xff) triple.rgbtBlue = 0xff; triple.rgbtGreen = 0xff; triple.rgbtRed = 0xff; }

fwrite(&triple, sizeof(RGBTRIPLE), i, outptr); }

fseek(inptr, padding, SEEK_CUR);

for (int k = 0; k < padding; k++)

{ fputc(0x00, outptr); }

}

fclose(inptr);

fclose(outptr);

return 0;

Implement a program called whodunit that reveals Mr. Boddys drawing in such a way that you can recognize whodunit.

Implement your program in a file called whodunit.c in a directory called whodunit.

Your program should accept exactly two command-line arguments: the name of an input file to open for reading followed by the name of an output file to open for writing.

If your program is executed with fewer or more than two command-line arguments, it should remind the user of correct usage, as with fprintf (to stderr), and main should return 1.

If the input file cannot be opened for reading, your program should inform the user as much, as with fprintf (to stderr), and main should return 2.

If the output file cannot be opened for writing, your program should inform the user as much, as with fprintf (to stderr), and main should return 3.

If the input file is not a 24-bit uncompressed BMP 4.0, your program should inform the user as much, as with fprintf (to stderr), and main should return 4.

Upon success, main should 0.

when I run it through the debugger I get

whodunit.c:9:5: error: expected identifier or '(' if (argc not_eq 3) ^ whodunit.c:15:16: error: use of undeclared identifier 'argv' char* infile = argv[1]; ^ whodunit.c:16:17: error: use of undeclared identifier 'argv' char* outfile = argv[2]; ^ whodunit.c:19:1: error: expected identifier or '(' if (inptr == (void *)0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!