user437777
user437777

Reputation: 1519

Passing Structure to function as argument in C

I am having this problem and Dont know the reason

I have this structure

typedef struct 
{

    Int32   frameID;
    Int32   slotIndx;
    Int32   symNumber;

}   recControlList;


    recControlList  *recControlListPtr;

Datatypes are typedefs.

Caller function is :

Fun( recControlListPtr);

Fun declaration is

Fun (recControlList *recControlListPtr);


syntax error : missing ')' before '*'

How to I pass structure as pointer into the function? Please help

Upvotes: 1

Views: 5412

Answers (4)

user2599989
user2599989

Reputation: 1

You can refer http://fresh2refresh.com/c/c-passing-struct-to-function/ website. Very simple example program is given for Passing structures to function by address. I hope this will be useful for you.

Upvotes: 0

davmac
davmac

Reputation: 20631

The declaration is missing a return type, eg:

void Fun (recControlList *recControlListPtr);

(edit: As pointed out by others, the return type in function declarations is optional in some variants of C, but it's good style and it can give you a better error message due to disambiguation).

Upvotes: 2

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

You need to have the struct declaration and typedef before the declaration of Fun().

If all of this in the same file, then they are just in the wrong order. If the struct is declared in a different file, you need to #include that before the function prototype.

EDIT : So on your second question...

Upvotes: 3

Stefan Steiger
Stefan Steiger

Reputation: 82186

You just pass it, such as in

char* xy = "HelloWorld";
if(!strcmp(xy, "HelloWorld"))

You can also do a

struct xy ;
functionName(&xy);

Did you specify a return value for your function?

Upvotes: 0

Related Questions