Been codeing all night can't seem to find the errors in this code. I expect they are obvious but can't see them with tired eyes. Using gcc for Cygwin as complier

Code:
/* This is a program that reads the header and colour table from a .bmp file */
/* to see if data has been hidden with STools.				     */
/* It does this by looking for duplication in the colour table		     */

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

typedef _bmp_header {
	char ID[2]
	int size;
	char res1[2], res2[2];
	int offset;
} bmp_header;

typedef struct _bmp_info {
	int size, width, height;
	int planes, BitsPerPixel;
	int compress, BMsize;
	int Hres, Vres;
	int CloursUsed, ColoursImportant;
} bmp_info;

/* Prototypes */
void load_bmp_header(FILE *BMP bmp_header *BH);
void load_bmp_info(FILE *BMP bmp_info *BI);

int main(int argc, char* argv[]) {
	int i,j,i1;
	int Dflag, Cflag, BMPsize, num_colours, dup_colours;
	FILE *BMPin;
	unsigned char_cloour_map[1024];
	bmp_header BMPHead;
	bmp_info BMPInfo;

/* Intialisation */
Dflag = 0;
Cflag = 0;

if(argc < 2) {
	fprintf(stderr, "Error: No bmp file\n");
	fprintf(sderr, "Usage SDetect [-d -c] bmp_file\n");
	fprintf(stderr, " -d gives file details\n -c prints out colour map");
	exit(1);
}

/* Look fo command-line flags */
for (i=1; i<(argc-1); i++) {
	if (argv[i][0] == '-') {
		switch (argv[i][1] {
		case 'h':
	printf("Usage: SDetect [-d -c] bmp_file\n");
	printf(" -d gives file details\n -c prints out colour map");
	exit(1);
	break
		case 'c':
	Cflag = 1;
	break;
		case 'd':
	Dflag = 1;
	break;
		default:
	printf("Error: Unknown switch %s\n, argv[i]);
	printf(sderr, "Usage SDetect [-d -c] bmp_file\n");
	printf(stderr, " -d gives file details\n -c prints out colour map");
	exit(1);
	break;
		}
	}
}

BMPin = fopen(argv[argc-1], "rb");
if(BMPin ==0) {
	fprintf(stderr, "**Error** Unable to open input file%s\n", argv[argc-1]);
	exit(1);
}
fseek(BMPin, 0, 0);

load_bmp_header(BMPin, &BMPHead);
load_bmp_info(Bmpin, &BMPInfo);

/* Calculate number of colours in palette */
num_colours = (BMPHead.offset - 14 - BMPInfo.size)/4;

fread(colour_map, 1 BMPInfo.ColoursUsed*4, BMPin);

/* Find duplicat colours */
dup_colour = 0;
for(i=0; i<BMPInfo.ColoursUsed; i++) {
	for(J=0; J<BMPiNFO.ColoursUsed; j++) {
		i1 =abs(colour_map[4*i] - colour_map[4*j]) +
			abs(colour_map[4*i+1] - colour_map[4*j+1]) +
			abs(colour_map [4*i+2] - colour_map[4*j+2]);
		if((i1<4) && (i !=j)) { dup_colour++; }
	}
}

if(Cflag) {
	/* print out colour map */
	printf("Colour Map:\n");
	for(i=0; i<BMPInfo.ColoursUsed; i++) {
		printf(" %3d %3d %3d %3d %3d\n", i,
			colour_map[4*i], colour_map[4*i+1],
			colour_map[4*i+2], colour_map[4*i+3]);
	}
}
fseek(BMPin, BMPHead.offset, 0);

printf(File Name: %s\n", argv[argc-1];
if(Dflag) {
	printf(Width: 		%d Height:		%d/n",
		BMPInfo.width, BMPInfo.height);
	printf("BitsPerPixel: 	%d NumBitPlanes:	%d/n",
		BMPInfo.BitsPerPixel, BMPInfo.planes);
	printf("Compression: %d\n", BMPInfo.compress);
	printf("Colours Used: %d	Colours Important: %d\n\n", 
		BMPInfo.ColoursUsed, BMPInfo.ColoursImportant);

	printf("actual size: %d	Reported: %d\n",
		BMPsize, BMPHead.size);
	printf("Duplicate colours: %d\n", dup_colour);
	printf("File header: Bytes 0 - 13\n")
	printf("Bitmap header: Bytes 14 - %3d/n", 13+BMPInfo.size);
	printf("Colour map: Bytes %3d - %3d\n",
		14+BMPInfo.size, 13+BMPInfo.size+4*BMPInfo.ColoursUsed);
	printf(Image data: Bytes %3d - %3d\n\n", BMPHead.offset,
		BMPHead.offset-1+		
		(BMPInfo.width*BMPInfo.height*BMPInfo.BitsPerPixel+7)/8);
}

if(dup_colour < 100) printf("Data has NOT been hidden in this file with STools");
if(dup_colour >= 100) printf(*** Data HAS BEEN HIDDEN in this file with STools ***")
printf("\n\n");

fclose(BMPin);
}

void load_bmp_header(FILE *BMP, bmp_header *BH) {
	unsigned char buffer[16];
	
	memset(BH, 0, sizeof(bmp_header));
	fread(buffer, 1, 14, BMP);

	memcpy(BH->ID, buffer, 2)
	if ((BH->ID[0] != 'B') || (BH->ID[1] != 'M')) {
		printf("Error: Bad file ID - not a BMP file\n");
		exit(1);
	}
	memcpy(&(BH->SIZE), buffer+2, 4);
	memcpy(BH->res1, buffer+6, 2);	
	memcpy(BH->res2, buffer+8, 2);
	memcpy(&(BH->offset), buffer+10, 4);
}

void load_bmp_info(FILE *BMP, bmp_info *BI) {
	unsigned char buffer[112];
	
	memset(BI, 0 sizeof(bmp_info));
	fread(buffer, 1, 108, BMP);

	memcpy(&(BI->size), buffer, 4);
	if((BI->size != 40) && (BI-> !=108)) {
		printf(BitmapInfo header size is %d - cannot handle this format\n",BI->size);
		exit(1)
	}

/* Reset position to beginning of colour table */

if(BI->size ==40) { fseek(BMP, -68, 1); }
	
	memcpy(&(BI->width), buffer+4, 4);
	memcpy(&(BI->height), buffer+8, 4);
	BI->planes = buffer[12]+256*buffer[13];
	BI->BitsPerPixel = buffer[14]+256*buffer[15];

	memcpy(&(BI->compress), buffer+16, 4);
	memcpy(&(BI->BMsize), buffer+20, 4);
	memcpy(&(BI->Hres), buffer+24, 4);
	memcpy(&(BI->Vres), buffer+28, 4);
	memcpy(&(BI->ColoursUsed), buffer+32, 4);
	memcpy(&(BI->ColoursImportant), buffer+36, 4);

if(BI->ColoursUsed ==0){
	BI->ColoursUsed = 1<< BI->BitsPerPixel;