943,829 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4863
  • C RSS
Dec 16th, 2008
0

pass a structure as reference parameter.

Expand Post »
plz explain how to do this the proper way.

  1. main.c
  2. =====
  3. struct names{ // definitions
  4. -----
  5. ----
  6. ----
  7. }
  8.  
  9. struct names x;
  10.  
  11. function1(&x);
  12.  
  13. file2.c
  14. ======
  15. function1(struct names *x){
  16. ----
  17. ----
  18. ----
  19.  
  20. }

am getting warning: 'struct names' declared inside parameter list
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
CoolAtt is offline Offline
39 posts
since Nov 2008
Dec 16th, 2008
0

Re: pass a structure as reference parameter.

I guess it's
  1. struct names{
  2. // ....
  3. } x;

or put it this way
  1. struct names{
  2. // ...
  3. };
  4.  
  5. struct names x;
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Dec 16th, 2008
0

Re: pass a structure as reference parameter.

about the warning am saying. any idea ?
Reputation Points: 10
Solved Threads: 0
Light Poster
CoolAtt is offline Offline
39 posts
since Nov 2008
Dec 16th, 2008
0

Re: pass a structure as reference parameter.

You're missing a semi-colon after defining the struct.

Should be:
struct names{  // definitions
-----
----
----
};
Reputation Points: 124
Solved Threads: 18
Junior Poster
devnar is offline Offline
148 posts
since Sep 2008
Dec 16th, 2008
0

Re: pass a structure as reference parameter.

its not that i think. i had put a semi-colon there.
Reputation Points: 10
Solved Threads: 0
Light Poster
CoolAtt is offline Offline
39 posts
since Nov 2008
Dec 16th, 2008
0

Re: pass a structure as reference parameter.

It's a good time to remember header files. Place the structure definition in .h file then include it in both main.c and file2.c. Now you have common structure (and other types) definition source.
A compiler knows nothing about main.c contents when processes file2.c.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: how do i right align my data?
Next Thread in C Forum Timeline: is fmod() recieving overflow?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC