2 Replies - 1677 Views - Last Post: 19 April 2012 - 05:23 AM Rate Topic: -----

#1 Noobscratcher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-July 11

How to use a structure variable array with a user defined function?

Posted 19 April 2012 - 03:03 AM

Hello I'm trying to figure out how to use a structure variable array like so :

This is the declaration of that struct :
 typedef struct tagCORD {
  LONG x;
  LONG y;
} CORD, *CCORD; 


This is the structure array being initialized :

int value; CORD Cord[value]; 


This is how I want to use my structure array in my user defined function declaration:

 void CordValues(cord[value], int p0x, int p0y, int p1x, int p1y, int p2x, int p2y)
  {
	Cord[0].x = p0x;
       Cord[0].y =  p0y;

	Cord[1].x = p1x;
	Cord[1].y = p1y;

	Cord[2].x = p2x;
	Cord[2].y =  p2y;
  } 



then in main :

  CordValues(cord[2], 100, 125, 200, 95, 270, 155, 270); 


So if you still don't understand let me explain it more in-depth

I want to create and be able to use the value of cord and use it within the above user defined function declaration as well as the scope of that user defined function declaration.


Thanks in Advance.

Is This A Good Question/Topic? 0
  • +

Replies To: How to use a structure variable array with a user defined function?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: How to use a structure variable array with a user defined function?

Posted 19 April 2012 - 03:48 AM

Thread moved to the C++ help forum. Please try not to post your questions in the Challenges subsection.
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon


Reputation: 4290
  • View blog
  • Posts: 13,454
  • Joined: 25-December 09

Re: How to use a structure variable array with a user defined function?

Posted 19 April 2012 - 05:23 AM

I see a couple of problems, the first is that your function prototype and your function call are not the same, one has 8 parameters the other has 7. Next when you declare an array your index value must be a compile time constant, unless you are compiling with a C compiler that allows VLA (Variable Length Arrays). Next in your function call when you use the brackets [2], means you are sending a pointer to a single instance of your structure to the function, not an array. You may want to read the function tutorials provided in my signature. They should help explain how to pass values into functions.

Jim

This post has been edited by jimblumberg: 19 April 2012 - 05:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1