problem with bmp load

hello , i had a code for loading the bmp file in c and my compiler is turbo c++ when i compile my code it has a unhandled exception : general protection exception, 0x215F:0x01BB Processor Fault, and my code is :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <conio.h>
#include <dos.h>

	  unsigned char buf[14][80];
void goto_xy(int x,int y);
void load_pic();
int main()
{
	 load_pic();
	 getch();
	 return 0;
}

void load_pic()
{
	  char fname[80];
	  FILE *fp;
	  register int i,j;
	  char far  *ptr= (char far *)0xB8000000;
	  char far  *temp;

	  temp=ptr;
	  for(i=0;i<14;i++)
	  for(j=0;j<80;j+=2){
								buf[i][j]=*temp;
								buf[i][j+1]=*(temp+8152);
								*temp=0;
								*(temp+8152)=0;
								temp++;
								}
	  goto_xy(0,0);
	  printf("enter file name: ");
	  gets(fname);
	  fp=fopen(fname,"rb");
	  if(fp==NULL){
						printf("cannot open the file,press a key...");
						temp=ptr;
                  for(i=0;i<14;i++)
						for(j=0;j<80;j+=2){
                                     *temp=buf[i][j];
												 *(temp+8152)=buf[i][j+1];
                                     temp++;
												 }
                  return ; 
						}
                  for(i=0;i<8152;i++){
												  *ptr=getc(fp);
                                      *(ptr+8152)=getc(fp);
                                      ptr++;
												  }
                  fclose(fp);
                  }

                  
                  
void goto_xy(int x,int y)
{
     union REGS r;
	  r.h.ah=2;
     r.h.dl=y;
     r.h.dh=x;
	  r.h.bh=0;
     int86(0x10,&r,&r);
}




can anyone help me with this ?
In the meantime some new operating systems were developed, such as Windows and Linux. You might want to catch up on these latest developments, as DOS is considered outdated by some people. Not to mention that no official C++ standard existed back then.

You should use a debugger to check which line causes the protection fault.
If something like that exists for your system.

char far *ptr= (char far *)0xB8000000;
I suppose there's no such thing as OS memory management?
the problem is with the line 26 (compiler highlight it) , and about the line you mentioned it actually save the 0xB8000000 (address of starting colorful screen memory ) and tell the compiler that we are saving it as a pointer
Just to verify, you're actually working in DOS, yes?
Because you can't write to arbitrary addresses in a modern OS.
Topic archived. No new replies allowed.