access violation?????

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# include <iostream>
# include "graph1.h"


using namespace std;

void getData(int* no_rects);
int* getXCoords(int no_rects);
int* getYCoords(int no_rects);
void displayRectangles(int no_rects, int* x, int* y);

int main()
{
	int no_rects=0;
	int x=NULL;
	int y=NULL;
	int *y_coords=NULL;
	int *x_coords=NULL;
	
	//Get the data for number of rectangles
	getData(&no_rects);

	x_coords = getXCoords(no_rects);

	y_coords = getYCoords(no_rects);
	
	displayRectangles(no_rects,x_coords,y_coords);

	delete[] y_coords;
	delete[] x_coords;

	return 0;
}

void getData(int* no_rects)
{
	cout<<"How many rects";
	cin>>*no_rects;
	}
int* getXCoords(int no_rects)
{
		int i=0;
		int* x_coords=new int[no_rects];
	
	for (i=0; i<no_rects;i++)
	{
		cout<<"Enter the x_coord for rect #"<<(i+1)<<":";
		cin>>x_coords[i];
	}
	return(x_coords);
}
int* getYCoords(int no_rects)
{
	int i =0;
	int* y_coords=new int[no_rects];
	for (i=0;i<no_rects;i++)
	{
		cout<<"Enter the y_coord for rect #"<<(i+1)<<":";
		cin>>y_coords[i];
	}
	return(y_coords);

}
void displayRectangles(int no_rects, int* x_coords, int* y_coords)
{
	int i=0;
	int obj_no = 0;

	for (i=0;i<no_rects;i++)
	{
		obj_no = drawRect(x_coords[i],y_coords[i],50,25);

		if (i%2 ==0)
		{
				setColor(obj_no,255,0,0);
		}
		else
		{
			setColor(obj_no,0,0,255);
		}
	}
}




it is showing I am having an access violoation

Unhandled exception at 0x10004805 in practice 2.exe: 0xC0000005: Access violation reading location 0x00000044.

its showing it breaks at this line

obj_no = drawRect(x_coords[i],y_coords[i],50,25);

any ideas?
try this
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
int** getXCoords(int no_rects);
int** getYCoords(int no_rects);

int** y_coords=NULL;
int** x_coords=NULL;

int** getXCoords(int no_rects)
{
		int i=0;
		int* x_coords=new int[no_rects];
	
	for (i=0; i<no_rects;i++)
	{
		cout<<"Enter the x_coord for rect #"<<(i+1)<<":";
		cin>>x_coords[i];
	}
	return &x_coords;
}
int** getYCoords(int no_rects)
{
	int i =0;
	int* y_coords=new int[no_rects];
	for (i=0;i<no_rects;i++)
	{
		cout<<"Enter the y_coord for rect #"<<(i+1)<<":";
		cin>>y_coords[i];
	}
	return &y_coords;

}
Topic archived. No new replies allowed.