Hi everyone

I am trying to read and print the negative of a 8 bit gray scale .bmp image with the following code, unfortunately it reads only 2 of the .bmp images i have, but doesn't read the other .bmp images including the one i have attached lena256.bmp, even though its an 8 bit greyscale .bmp image.
All of them happen to have the same properties but with this code am unable to read all the .bmp files, only 2 wud give proper output :

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/*-------STRUCTURES---------*/
typedef struct {int rows; int cols; int bits; unsigned char* data;} sImage;

/*-------PROTOTYPES---------*/
long getImageInfo(FILE*, long, int);
void copyImageInfo(FILE*, FILE*);
void copyColorTable(FILE*, FILE*, int);

int main()
{
  FILE         *bmpInput, *bmpOutput;
  sImage      originalImage;
  unsigned char      someChar;
  unsigned char*   pChar;
  int         nColors;  /* BMP number of colors */
  long         fileSize; /* BMP file size */
  int         vectorSize; /* BMP vector size */
  int         r, c;       /* r = rows, c = cols */
  int           pixels[600][600];
  char imagein[30];
  char imageout[30];
  /* initialize pointer */
  someChar = '0';
  pChar = &someChar;
  printf("Enter input image : ");
  gets(imagein);
 
  printf("Enter output image : ");
  gets(imageout);
 
  /*--------READ INPUT FILE------------*/
  bmpInput = fopen(imagein, "rb");
  fseek(bmpInput, 0L, SEEK_END);
 
  /*--------DECLARE OUTPUT FILE--------*/
  bmpOutput = fopen(imageout, "wb");

  /*--------GET BMP DATA---------------*/
  originalImage.cols = (int)getImageInfo(bmpInput, 18, 4);
  originalImage.rows = (int)getImageInfo(bmpInput, 22, 4);
  originalImage.bits = (int)getImageInfo(bmpInput, 28, 4);
  fileSize = getImageInfo(bmpInput, 2, 4);
  nColors = getImageInfo(bmpInput, 46, 4);
  vectorSize = fileSize - (14 + 40 + 4*nColors);

  /*-------PRINT DATA TO SCREEN-------------*/
  printf("Width: %d\n", originalImage.cols);
  printf("Height: %d\n", originalImage.rows);
  printf("Bits per Pixel: %d\n", originalImage.bits);
  printf("File size: %ld\n", fileSize);
  printf("# Colors: %d\n", nColors);
  printf("Vector size: %d\n", vectorSize);
 
  copyImageInfo(bmpInput, bmpOutput);
  copyColorTable(bmpInput, bmpOutput, nColors);

  /*----START AT BEGINNING OF RASTER DATA-----*/
  fseek(bmpInput, (54 + 4*nColors), SEEK_SET);

  /*----------READ RASTER DATA----------*/
  for(r=0; r<=originalImage.rows - 1; r++)
  {
    for(c=0; c<=originalImage.cols - 1; c++)
    {
      /*-----read data, reflect and write to output file----*/
      fread(pChar, sizeof(char), 1, bmpInput);
      pixels[r][c] = *pChar;
      *pChar = 255 - *pChar;
      fwrite(pChar, sizeof(char), 1, bmpOutput);
    }
  }
 
  fclose(bmpInput);
  fclose(bmpOutput);
  getch();
}

/*----------GET IMAGE INFO SUBPROGRAM--------------*/
long getImageInfo(FILE* inputFile, long offset, int numberOfChars)
{
  unsigned char      *ptrC;
  long         value = 0L;
  unsigned char      dummy;
  int         i;

  dummy = '0';
  ptrC = &dummy;

  fseek(inputFile, offset, SEEK_SET);

  for(i=1; i<=numberOfChars; i++)
  {
    fread(ptrC, sizeof(char), 1, inputFile);
    /* calculate value based on adding bytes */
    value = (long)(value + (*ptrC)*(pow(256, (i-1))));
  }
  return(value);

} /* end of getImageInfo */

/*-------------COPIES HEADER AND INFO HEADER----------------*/
void copyImageInfo(FILE* inputFile, FILE* outputFile)
{
  unsigned char      *ptrC;
  unsigned char      dummy;
  int i;
  dummy = '0';
  ptrC = &dummy;

  fseek(inputFile, 0L, SEEK_SET);
  fseek(outputFile, 0L, SEEK_SET);

  for(i=0; i<=50; i++)
  {
    fread(ptrC, sizeof(char), 1, inputFile);
    fwrite(ptrC, sizeof(char), 1, outputFile);
  }
}

/*----------------COPIES COLOR TABLE-----------------------------*/
void copyColorTable(FILE* inputFile, FILE* outputFile, int nColors)
{
  unsigned char      *ptrC;
  unsigned char      dummy;
  int i;

  dummy = '0';
  ptrC = &dummy;

  fseek(inputFile, 54L, SEEK_SET);
  fseek(outputFile, 54L, SEEK_SET);

  for(i=0; i<=(4*nColors); i++)  /* there are (4*nColors) bytesin color table */
  {
    fread(ptrC, sizeof(char), 1, inputFile);
    fwrite(ptrC, sizeof(char), 1, outputFile);
  }

}
I would be really grateful if someone could go through this code and find out where am going wrong.

Thank you in advance.
Anna