nash83 0 Newbie Poster

Hello to everybody.I am using microsoft visual c++ compilator 7.0 for image processing.I have wrote down a program that opens a 24 bitmap image and loads it on a 800x 600 matrix after making the average of the RGB bytes.This because I would like to visualize it like a grey scale image.Is this possible?I mean after making the average and loading each value on the matrix how can I visualize it as grey level image?I post the code I hope someone can help me

//program to load a 24 color bitmap on a matrix and visualize its content

#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>


void load_bitmap(char *,int,int,void *);

void main(int argc, char *argv[])
{
	int i=0,j=0,w=0,h=0,t=0;
	unsigned char *buf = (unsigned char *)malloc(sizeof(unsigned char)*800*600*3);
                unsigned char       buff[800][600];  //this is the matrix where I want to lad the image
	char *name         =  "polyhedron10.bmp";    //this is the name of the image I want to load (it is present on .cpp file folder)

        load_bitmap(name,w,h,buf);           //member function to open the bitmap image
for(i=0; i<800; i++) for(j=0; j<600; j++){      //double for cycle to load the image
                buff[i][j]=(*(buf + t) + *(buf + t + 1) + *(buf + t + 2))/3;
                t=t+3;
	}	
    for(i=0; i<800; i++) for(j=0; j<600; j++){            //cycle to visualize content
		printf("%d,%d",i,j);
		printf("  %d\n  ",buff[i][j]);
		Sleep(5);
	}
}

void load_bitmap(char* filename,int width, int height, void* buffer)
{

	FILE*			     fp;

	if((fp = fopen(filename, "rb")) == NULL)    //check it is a bitmap image
	{
		printf("it is not a bitmap”s�B\n");
		return;
	}
	
	printf("pointer to fp is %d\n",fp);
	fread(buffer, sizeof(BYTE), 600*800*3, fp);  
	fclose(fp);
}