954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pass a structure as reference parameter.

plz explain how to do this the proper way.

main.c
=====
struct names{  // definitions
-----
----
----
} 

struct names x;

function1(&x);

file2.c
======
function1(struct names *x){
----
----
----

}


am getting warning:'struct names' declared inside parameter list

CoolAtt
Light Poster
39 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

I guess it's

struct names{
// ....
} x;


or put it this way

struct names{
// ...
};

struct names x;
verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 

about the warning am saying. any idea ?

CoolAtt
Light Poster
39 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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

Should be:

struct names{  // definitions
-----
----
----
};
devnar
Junior Poster
149 posts since Sep 2008
Reputation Points: 124
Solved Threads: 18
 

its not that i think. i had put a semi-colon there.

CoolAtt
Light Poster
39 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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.

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You