I have a problem on Lab4 of Harvard's CS50 course (intro to CS)
My code for Lab4 of CS50 course works well on my laptop but when I run check50 before submitting it, I get the following error code failed to compile. I know it can happen when you modify something else than what you are supposed to on the base code provided by the course but here, I only added code under the TODO comments (It's the least I can do to make it work. I also tried to remove the comments). Here is my code :
// Modifies the volume of an audio file
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Number of bytes in .wav header
const int HEADER_SIZE = 44;
int main(int argc, char *argv[])
{
// Check command-line arguments
if (argc != 4)
{
printf("Usage: ./volume input.wav output.wav factor\n");
return 1;
}
// Open files and determine scaling factor
FILE *input = fopen(argv[1], "r");
if (input == NULL)
{
printf("Could not open file.\n");
return 1;
}
FILE *output = fopen(argv[2], "w");
if (output == NULL)
{
printf("Could not open file.\n");
return 1;
}
float factor = atof(argv[3]);
// TODO: Copy header from input file to output file
u_int8_t header[44];
fread(&header, HEADER_SIZE, 1, input);
fwrite(&header, HEADER_SIZE, 1, output);
// TODO: Read samples from input file and write updated data to output file
int16_t buffer;
while (fread(&buffer, sizeof(int16_t), 1, input))
{
//Apply the factor to the buffer
buffer *= factor;
fwrite(&buffer, sizeof(int16_t), 1, output);
}
// Close files
fclose(input);
fclose(output);
}
Thanks by advance for any help !