Can anybody tell me what's wrong the link for check50 mistake is https://sandbox.cs50.net/checks/28278d1be858417299f79aab9879e519
when n was 2.
/**
* Copies a BMP piece by piece, just because.
*/
#include <stdio.h>
#include <stdlib.h>
#include "bmp.h"
int main(int argc, char *argv[])
{
// ensure proper usage
if (argc != 4)
{
fprintf(stderr, "Usage: ./resize positive integer value infile outfile\n");
return 1;
}
// remember filenames
char *infile = argv[2];
char *outfile = argv[3];
// open input file
FILE *inptr = fopen(infile, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", infile);
return 2;
}
// open output file
FILE *outptr = fopen(outfile, "w");
if (outptr == NULL)
{
fclose(inptr);
fprintf(stderr, "Could not create %s.\n", outfile);
return 3;
}
int fctr = atoi(argv[1]);
if (fctr <= 0 || fctr > 100)
{
fprintf(stderr, "positive integer must be between 0 and 100");
return 4;
}
// read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf, bf_out;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
bf_out = bf;
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi, bi_out;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
bi_out = bi;
// 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, "Unsupported file format.\n");
return 4;
}
// Updating out file width and height
bi_out.biWidth = bi.biWidth * fctr;
bi_out.biHeight = bi.biHeight * fctr;
// determine padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int padding_out = (4 - (bi_out.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
// Updating out file size
bi_out.biSizeImage = ((sizeof(RGBTRIPLE) * bi_out.biWidth) + padding_out);
bf_out.bfSize = bi_out.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
// write outfile's BITMAPFILEHEADER
fwrite(&bf_out, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi_out, sizeof(BITMAPINFOHEADER), 1, outptr);
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
// Write each line factor-times
for(int n = 0; n < fctr; n++)
{
// 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);
for(int m = 0; m < fctr; m++)
{
// 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
for (int k = 0; k < padding_out; k++)
{
fputc(0x00, outptr);
}
fseek(inptr, -(bi.biWidth * 3 + padding ), SEEK_CUR);
}
fseek(inptr, bi.biWidth * 3 + padding, SEEK_CUR);
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// success
return 0;
}
{}
button in the editor). – Blauelf May 5 '17 at 11:55