0

I tried changing the red to white in verdict. I see no difference at all after running ./whodunit or ./whodunit clue verdict . What am I missing? Verdict shows the red dot indicating that it needs to be saved, so I also tried saving the verdict file directly. It then prompts me to save it as an html file, then when I try to open as an html file I see 'there is supposed to be content here but the publisher doesn't allow it to be displayed in a frame.'

Here is my code:

// Copies a BMP file

#include <stdio.h>
#include <stdlib.h>

#include "bmp.h"

int main(int argc, char *argv[])
{
    // ensure proper usage
    if (argc != 3)
    {
        fprintf(stderr, "Usage: ./whodunit infile outfile\n");
        return 1;
    }

    // remember filenames
    char *infile = argv[1];
    char *outfile = argv[2];

    // open input file for reading
    FILE *inptr = fopen(infile, "r");
    if (inptr == NULL)
    {
        fprintf(stderr, "Usage: ./whodunit infile outfile\n");
        // fprintf(stderr, "Could not open %s.\n", infile);
        return 2;
    }

    // open output file for writing
    FILE *outptr = fopen(outfile, "w");
    if (outptr == NULL)
    {
        fclose(inptr);
        fprintf(stderr, "Usage: ./whodunit infile outfile\n");
        // fprintf(stderr, "Could not create %s.\n", outfile);
        return 3;
    }

    // read infile's BITMAPFILEHEADER
    BITMAPFILEHEADER bf;
     //Update header for output file
    //Copy.c’s fread(data, size, number, inptr) See 2.56, 3.05
    // data is pointer to a struct containing bytes I'm reading
    fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

    // read infile's BITMAPINFOHEADER
    BITMAPINFOHEADER bi;
    fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);

    // ensure infile is (likely) a 24-bit uncompressed BMP 4.0
    if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
        bi.biBitCount != 24 || bi.biCompression != 0)
    {
        fclose(outptr);
        fclose(inptr);
        fprintf(stderr, "Usage: ./whodunit infile outfile\n");
        // fprintf(stderr, "Unsupported file format.\n");
        return 4;
    }

    // write outfile's BITMAPFILEHEADER
    //Update header for output file
    //Copy.c’s fread(data, size, number, inptr) See 2.56, 3.05
    // data is pointer to a struct containing bytes I'm reading
    fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);

    // write outfile's BITMAPINFOHEADER
    fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);

    // determine padding for scanlines
    int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

    // iterate over infile's scanlines
    for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
    {
        // iterate over pixels in scanline
        for (int j = 0; j < bi.biWidth; j++)
        {
            // temporary storage
            RGBTRIPLE triple;

            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
            if (triple.rgbtBlue == 0x00 && triple.rgbtGreen == 0x00 && triple.rgbtRed == 0xff)
            {
                triple.rgbtBlue = 0xff;
                triple.rgbtGreen = 0xff;
                triple.rgbtRed = 0xff;
            }

            // write RGB triple to outfile
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
        }

        // skip over padding, if any
        fseek(inptr, padding, SEEK_CUR);

        // then add it back (to demonstrate how)
        for (int k = 0; k < padding; k++)
        {
            fputc(0x00, outptr);
        }
    }

    // close infile
    fclose(inptr);

    // close outfile
    fclose(outptr);

    // success
    return 0;
}
0

Hi i would recommend you to re-read the pset again at https://docs.cs50.net/2018/x/psets/4/whodunit/whodunit.html to understand how copy.c or whodunit.c works! I ran your code the right way and its fine (although its slightly difficult for the eyes to spot the answer.)

tldr: the command line arguments you used to run your code are incorrect.

1
  • OMG, thank you! Can't believe I missed that in the instructions, all I had to do was add the .bmp file extensions to the command line arguments! – Marie Urbina May 27 '18 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .