Re: How to pass a struct to a function
- From: "Bill" <bill.warner@xxxxxxxxxxxx>
- Date: 28 Mar 2007 08:22:05 -0700
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;
}
.
- Follow-Ups:
- Re: How to pass a struct to a function
- From: Keith Thompson
- Re: How to pass a struct to a function
- From: Richard Heathfield
- Re: How to pass a struct to a function
- References:
- How to pass a struct to a function
- From: Bill
- Re: How to pass a struct to a function
- From: Chris Dollin
- How to pass a struct to a function
- Prev by Date: Re: how do you pass an array by value
- Next by Date: Re: Is it a good thing that program mix C and C++?
- Previous by thread: Re: How to pass a struct to a function
- Next by thread: Re: How to pass a struct to a function
- Index(es):
Relevant Pages
|