title: Reading a bmp file and inverting it in C
body: <p>I have an assignment that deals with reading a bmp file into memory, inverts the pixels, and then saves the inverted image to a new file. From this description it seems fairly easy, however I don't think my professor did a great job in explaining the necessary steps to go about doing so. He taught us about fread and fwrite but there is so much more. Can anyone explain the process in going about this problem (I'm no looking for a direct answer just an explanation). </p>
  
  <p>Here is the link to the problem's description: <a href="https://engineering.purdue.edu/OOSD/F2012/Exercises/ex5.html/" rel="nofollow" title="Ex.5">https://engineering.purdue.edu/OOSD/F2012/Exercises/ex5.html</a></p>
  
  <p>Thanks in advance for any sort of help.
  NOTE: I actually have looked into this problem but since I don't have a good standing on this info it's not quite "clicking".</p>
  
  <p>I guess the part that I am stuck on right now is:</p>
  
  <pre><code>    /* The input argument is the source file pointer. The function will first construct a BMP_Image image by allocating memory to it.
   * Then the function read the header from source image to the image's header.
   * Compute data size, width, height, and bytes_per_pixel of the image and stores them as image's attributes.
   * Finally, allocate menory for image's data according to the image size.
   * Return image;
  */
  BMP_Image* CreateBMPImage(FILE* fptr)
  {
  
    //Allocate memory for BMP_Image*;
  
    //Read the first 54 bytes of the source into the header
  
    //Compute data size, width, height, and bytes per pixel;
  
    //Allocate memory for image data
  }
  </code></pre>
  
  <p>The BMP_Image structure looks like this:</p>
  
  <pre><code>typedef struct {
      BMP_Header header;
      int data_size;
      int width;
      int height;
      int bytes_per_pixel; // This amount should be equals to number of bits/8
      char *data;
  } BMP_Image;
  </code></pre>