anonymous
  • anonymous
C Question: How do you pass structures (or structure fields) as function parameters?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
arnavguddu
  • arnavguddu
use pass by pointer.... struct mystruct { ... }; void passthestruct(struct mystruct* p) { // use the structure pointer } pass by value: void passstructbyvalue(struct mystruct v) { } just like passing variable to function
anonymous
  • anonymous
I declared my structures using typedef: typedef struct { char OrigCurr[4]; char WantCurr[4]; float ExRate; } STRUCTTYPE_Rates; typedef struct { char User[31]; char Pass[31]; char Role[14]; } STRUCTTYPE_Users; STRUCTTYPE_Rates STRUCT_Rates[100]; STRUCTTYPE_Users STRUCT_Users[100]; I'm trying to pass the parameter by pointer: int TXTDATA_Read_Rates(STRUCTTYPE_Rates* STRUCT_Rates, FILE *STREAM_Rates) { //blahblah } int TXTDATA_Read_Users(STRUCTTYPE_Users* STRUCT_Users, FILE *STREAM_Users) { //blahblah } Now when I compile, i get the following error message, for both lines above: error: expected ‘)’ before ‘*’ token What am I doing wrong?
anonymous
  • anonymous
I'm using gcc btw. I'm required to.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Also, my struct declarations are in the main function. Is there a way to do what I want without making the structures global?
arnavguddu
  • arnavguddu
change the structure declarations as... typedef struct _mystruct { fields... } mystruct; here the error maybe due to structure name is not declared. Alternate: struct _mystruct { fields }; typedef struct _mystruct mystruct;
anonymous
  • anonymous
I've got these errors from trying to compile the attached .c file: test.c:74: error: expected ‘)’ before ‘a’ test.c:99: error: expected ‘)’ before ‘STRUCT_Users’ test.c:153: error: expected ‘)’ before ‘STRUCT_Users’ test.c:175: error: expected ‘)’ before ‘STRUCT_Users’ test.c:210: error: expected ‘)’ before ‘STRUCT_Users’
1 Attachment

Looking for something else?

Not the answer you are looking for? Search for more explanations.