Can any1 help me too debugg this program..........pls...........
if possible post d debugged program here itself or mail it to me <<>>
thank u in advance :)
the following is a program of edge detection in an image..........i m gettin errors in both dev C++ and Code blocks

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
#define GRAPHICS 0x13
#define TEXT  0x03
#define N 16
#define ROWMAX 128
#define COLMAX 128
#define THRESHOLD 200
union REGS regs;
unsigned char image[ROWMAX][COLMAX];
int new_image[ROWMAX][COLMAX];
void get_image_data(void) //function to read the raw file.
{
char filename[30];
int i,j;
FILE *fp;
printf("\n The program implements various edge detection techniques");
printf("Enter the name of d file");
cin>>filename;
fp=fopen(filename,"rb");
if(fp==NULL)  /*file could not be opened */
{
cout<<"\n\t The specified file is unreadable";
exit(1);
}
for(i=0;i<ROWMAX;i++) /* scan pixel data */
for(j=0;j<COLMAX;j++)
fscanf(fp,"%c",&image[i][j]);
fclose(fp);
}
void apply_prewitt_y(void)
{int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	     temp=(int)(-1.0*(int)image[i-1][j-1]
			-1.0*(int)image[i-1][j]
			-1.0*(int)image[i-1][j+1]
			+0.0*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+0.0*(int)image[i][j+1]
			+1.0*(int)image[i+1][j-1]
			+1.0*(int)image[i+1][j]
			+1.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void apply_prewitt_x(void)
{
int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	     temp=(int)(-1.0*(int)image[i-1][j-1]
			+0.0*(int)image[i-1][j]
			+1.0*(int)image[i-1][j+1]
			-1.0*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+1.0*(int)image[i][j+1]
			-1.0*(int)image[i+1][j-1]
			+0.0*(int)image[i+1][j]
			+1.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void apply_isotropic_x(void)
{int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	     temp=(int)(-1.0*(int)image[i-1][j-1]
			+0.0*(int)image[i-1][j]
			+1.0*(int)image[i-1][j+1]
			-1.414*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+1.414*(int)image[i][j+1]
			-1.0*(int)image[i+1][j-1]
			+0.0*(int)image[i+1][j]
			+1.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void apply_isotropic_y(void)
{int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	 temp=(int)(-1.0*(int)image[i-1][j-1]
			-1.414*(int)image[i-1][j]
			-1.0*(int)image[i-1][j+1]
			+0.0*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+0.0*(int)image[i][j+1]
			+1.0*(int)image[i+1][j-1]
			+1.414*(int)image[i+1][j]
			+1.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void apply_sobel_y(void)
{int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	 temp=(int)(-1.0*(int)image[i-1][j-1]
			-2.0*(int)image[i-1][j]
			-1.0*(int)image[i-1][j+1]
			+0.0*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+0.0*(int)image[i][j+1]
			+1.0*(int)image[i+1][j-1]
			+2.0*(int)image[i+1][j]
			+1.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void apply_sobel_x(void)
{int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	 temp=(int)(-1.0*(int)image[i-1][j-1]
			+0.0*(int)image[i-1][j]
			+1.0*(int)image[i-1][j+1]
			-2.0*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+2.0*(int)image[i][j+1]
			-1.0*(int)image[i+1][j-1]
			+0.0*(int)image[i+1][j]
			+1.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void apply_slant(void)
{int i,j,k;
 int temp;
for(i=1;i<ROWMAX-1;i++)
    {
     for(j=1;j<COLMAX-1;j++)
	{
	 temp=(int)(0.0*(int)image[i-1][j-1]
			+1.0*(int)image[i-1][j]
			+2.0*(int)image[i-1][j+1]
			-1.0*(int)image[i][j-1]
			+0.0*(int)image[i][j]
			+1.0*(int)image[i][j+1]
			-2.0*(int)image[i+1][j-1]
			-1.0*(int)image[i+1][j]
			+0.0*(int)image[i+1][j+1]);
	if(temp<0)
	   temp=0;
	if(temp>255)
	   temp=255;
	new_image[i][j]=(int)temp;
	}
  }
}
void copy_image(void)
{
int i,j,k;
for(i=0;i<ROWMAX;i++)
{
 for(j=0;j<COLMAX;j++)
 {
  if(i==0||j==0)
    image[i][j]=(unsigned char)0;
 else
    image[i][j]=(unsigned char)new_image[i][j];
  }
 }
}
void write_file(void)
{
 int i,j;
FILE *fp2;
fp2=fopen("filter.raw","wb");
if(fp2==NULL)  //file could not be opened
{
printf("Unable to open file");
fclose(fp2);
getch();
exit(1);
}
for(i=0;i<ROWMAX;i++)
for(j=0;j<COLMAX;j++)
fprintf(fp2,"%c",new_image[i][j]);
}
void set_mode(char mode)
{
regs.h.ah=0x00;
regs.h.al=mode;
int86(0x10,&regs,&regs);
}
void set_palette(void)
{
int i;
regs.h.ah=0x10;
regs.h.al=0x10;
for(i=0;i<256;i++)
{
regs.h.cl=(unsigned char)i>>2;
regs.h.ch=(unsigned char)i>>2;
regs.h.dh=(unsigned char)i>>2;
regs.x.bx=i;
int86(0x10,&regs,&regs);
}}
void show(unsigned char image[ROWMAX][COLMAX],int  x ,int  y )
{
int i,j;
for(i=0;i<ROWMAX;i++)
for(j=0;j<COLMAX;j++)
{
regs.h.ah=0x0c;
regs.h.al=image[i][j];
regs.x.cx=y+j;
regs.x.dx=x+i;
int86(0x10,&regs,&regs);
}}
void main()
{
int choice;
clrscr();
get_image_data();
printf("\nenter choice of mask");
printf("\n 1) Prewitt(x) \n 2)Prewitt(y) \n 3)Sobel(x) \n 4)Sobel(y)");
printf("\n 5)Isotropic(x) \n 6)Isotropic(y) \n 7)Slant(x) \n 8)Exit(y) \n Choice");
scanf("%d",&choice);
set_mode(GRAPHICS);
set_palette();
show(image,45,0);
switch(choice)
{
case 1:
      apply_prewitt_x();
      break;
case 2:
      apply_prewitt_y();
      break;
case 3:
      apply_sobel_x();
      break;
case 4:
      apply_sobel_x();
      break;
case 5:
      apply_isotropic_x();
      break;
case 6:
      apply_isotropic_y();
      break;
case 7:
      apply_slant();
      break;
case 8:
   exit(0);
}
copy_image();
write_file();
show(image,450,50);
getch();
set_mode(TEXT);
}

Recommended Answers

All 2 Replies

You should also give the errors with line numbers.

you defined that

#include<dos.h>

so that means this is a program that written to the old pain DOS environment.
Try with the turbo C++ v3.0 or djgpp if you can't find turbo C++.

I seek is there any way that you can compile dos under codelite ? well the mingw
supports to build dos executables but you have to manually give that compiler
option. mingw may support the dos plactform as a plugin ,you have to configure and
install that plugin or either download djgpp and configure your ide for that.

or simply find turbo C++ v3.0 somehow.

BTW: anyway why you want to keep developing in DOS ? you read the code and translate
it to win32 , I'll give whatever help in translating as I can,probablly somebody
here will probablly help you on this further.

instead #include<dos.h> you can now write #include<windows.h> :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.