Re: How to pass a struct to a function



On Mar 28, 9:48 am, Chris Dollin <chris.dol...@xxxxxx> wrote:
Bill wrote:
I am trying to pass a struct to a function. How would that best be
accomplished?

Assuming that the function has an argument of the right structure type,
write an expression evaluating to your struct -- the name of a variable
of that struct type is popular -- in the appropriate argument position
in a call to that function.

What am I missing?

--
The second Jena users conference -- be there or have rdf:type geometric:Square.
"What I don't understand is this ..." Trevor Chaplin, /The Beiderbeck Affair/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Here is what I have so far, won't even compile. And I am:

#include <stdio.h>
#include <string.h>

int AddEntry(struct entry);

struct{
char fName[51];
char lName[51];
char Phone[13];
}Entry;

int main()
{
int retCode;

Entry.fName = "Fred";
Entry.lName = "Flintstone";
Entry.Phone = "123-456-7890";

retCode = AddEntry(Entry);
}

//int AddEntry(char fName[51], char lName[51], char Phone[13])
int AddEntry(struct entry)
{
FILE *fp;

fp = fopen("AppData.dat", "a"); /* open file for writing */

fprintf(fp, "%s", fName); /* write some info */
fprintf(fp, "\t");
fprintf(fp, "%s", lName);
fprintf(fp, "\t");
fprintf(fp, "%s", Phone);
fprintf(fp, "\n");

fclose(fp); /* close the file */

return 1;
}

.



Relevant Pages