2 Replies - 2159 Views - Last Post: 15 October 2008 - 12:09 AM Rate Topic: -----

#1 prads  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 22-October 07

structure passed within function

Post icon  Posted 14 October 2008 - 01:56 PM

Hello,
In my C++ code, I want to pass a structure as a function parameter. This is what I do:
struct funcpar
{
int loop,dex3[2][50];
char *Buf;
double wfc;
}param;

main{
void myfunc(struct funcpar param);
//statements;
//statements;
//statements;
myfucn(param);
////statements;
//statements;
}
void myfunc(struct funcpar param)
{
//statements;
//statements;
return 0;
}


Is the above syntax correct?

Initially I had those elements in the structure funcpar{} as the parameters within the function. Instead of passing 4+ parameter I thought of passing them as a structure. I however used the appropriate "." reference wherever applicable.
My code is throwing an exception which points at the myfunc(param) function call within main().
Please guide me.


Regards,
prads

Is This A Good Question/Topic? 0
  • +

Replies To: structure passed within function

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: structure passed within function

Posted 14 October 2008 - 02:13 PM

Don't forget the keyword "typedef" at the beginning of your struct if you are going to rename it param. Also watch it because you have a misspelling in your call to myfunc... you have "myfucn".

Other than that, all is cool so far. :)
Was This Post Helpful? 0
  • +
  • -

#3 RedSonja  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 172
  • Joined: 04-September 08

Re: structure passed within function

Posted 15 October 2008 - 12:09 AM

If you really want myfunc to return an integer then you will have to declare it that way.

int myfunc(...)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1