Hi, i have a problem with passing the array of structs into another function. Line 15 and 20 - errors. Here the code

#include<stdio.h>
struct point
{
	int x;
	int y;
}pointar[3]; 
typedef struct point POINT;
struct circle
{
	int x;
	int y;
	float radius;
}circlear[3]; 
typedef struct point CIRCLE;
void fun (POINT *pointar, CIRCLE *circlear);
void main ()
{
	........

	fun (pointar, circlear);
}

thanks in advance

In this code:

typedef struct point CIRCLE;

did you mean:

typedef struct circle CIRCLE;

??
;) ;)
Funny, but I've done that kind of stuff many times, myself.

In C, it's always int main, never void main, and with a return 0 at the end. You should be getting a warning or error about that.

ooops i didnt even notice that.. thanks i fixed it.. but i still get: "/tmp/ccoyO4Cb.o: In function `main':
2.c: (.text+0xf2): undefined reference to `fun'
collect2: ld returned 1 exit status"

change your function call to:

fun (&pointar, &circlear);

i added & when i call fun
2.c: In function ‘main’:
2.c:20: warning: passing argument 1 of ‘fun’ from incompatible pointer type
2.c:15: note: expected ‘struct POINT *’ but argument is of type ‘struct point (*)[3]’
2.c:20: warning: passing argument 2 of ‘fun’ from incompatible pointer type
2.c:15: note: expected ‘struct CIRCLE *’ but argument is of type ‘struct circle (*)[3]’
/tmp/ccR3rEA9.o: In function `main':
2.c: (.text+0xf2): undefined reference to `fun'
collect2: ld returned 1 exit status

I'm not sure what you're trying to do here, are you messing with us or what?

You need three things for a function call:

1) The call - we've got that
2) The function prototype - we've got that
3) The function itself - and we don't have that

You have declared pointar and circlear as global arrays of three structs. That means you don't need to pass them to any function, and it's an error to do so (your compiler may not mind, but the result will be nothing you wanted will happen).

So I'm really confused what you're trying to do here - post what you want, and post the whole friggin' program (a working example is fine), and let's quit the hide and seek with the code, game.

You have to be specific - do you want the pointar and circlear arrays global or local, etc.

sorry, i didn't think the actual program really mattered, since i just cannot pass those two structs in a fucntion, i know what you are talking about, since its global thats what i did, without passing it to a function and it worked, but since its my assignment. Here's the question: "Write a function that takes a point and a circle as input, and determines whether the point is inside, on,or outside the circle."
heres my working code without passing the structs

#include<stdio.h>
struct point
{
	int x;
	int y;
}pointar[3]; 
typedef struct point POINT;
struct circle
{
	int x;
	int y;
	float radius;
}circlear[3]; 
typedef struct circle CIRCLE;
void fun ();
void main ()
{
	int i;
	printf ("Enter 3 points\n");
	for(i=0;i<3;i++)
	{
		scanf ("%d %d", &pointar[i].x, &pointar[i].y);
	}
	printf ("Enter 3 circles\n");
	for (i=0;i<3;i++)
	{
		scanf ("%d %d %f", &circlear[i].x, &circlear[i].y, &circlear[i].radius);
	}
	fun ();
}	
void fun ()
{
	int i=0,j;
	while (i<3)
	{
		for (j=0;j<3;j++)
		{			
			if(((pointar[j].x-circlear[i].x)^2)+((pointar[j].y-circlear[i].y)^2)<=(((int)circlear[i].radius)^2))
			{
				printf ("Point: [%d, %d] is inside Circle: [%d, %d, %.0f]\n", pointar[j].x, pointar[j].y, circlear[i].x, circlear[i].x, circlear[i].radius);
			}
			else 
			{
				printf ("Point: [%d, %d] is outside Circle: [%d, %d, %.0f]\n", pointar[j].x, pointar[j].y, circlear[i].x, circlear[i].x, circlear[i].radius);	
			}
		}
		i++;
	}
}

Now, we're getting somewhere, at last.

First, you know the arrays have to be local, so remove them from above main() and declare them inside main().

Second, the name of the array is a constant pointer (almost!) to the base of the array, so let's make the call to the function, with just the two names of the pointer.

Third, the receiving function will take these two arrays as pointers to the struct array, which you have already typedef'ed, so this kind of a function parameter list, should be OK:

void fun (POINT *pointar, CIRCLE *circlear);

If the 3 is something that might be changed later, let's do a #define MAX 3 statement, (note no = char and no semi-colon either), right below the #include file list. In fact, it's such a darn good idea, let's do this define, anyway. It's a great habit to get into.

Then see what errors you're getting, and please re-post the program so we aren't talking about what was - only what is.

And you can please lose the void main() -- that is not C.

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.