Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

structure => function => main => another function

Status
Not open for further replies.

jdarvwill

Technical User
May 22, 2002
12
CA
hi, i need a structure to be passed to a function, filled with data, returned to main, and then passed to another function with data intact. I can get it to recieve the data from the 1st function and return to main retaining the data. I just can't get it to pass to another function with data intact.

any ideas? thanks :)
 
kindly post your code so that we could help you out by fixing your code .
 
Heres a small example of what you can do... Just something to think about ;-)

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

typedef struct tagData
{
int month,
day,
year;

char message[32];
}data_t;

void first_function(data_t *d);
void second_function(data_t *d);

main()
{
data_t mydata;

first_function(&mydata);
second_function(&mydata);

return 0;
}

void first_function(data_t *d)
{
d->month = 7;
d->day = 5;
d->year = 2002;

strcpy(d->message, &quot;The day is:&quot;);
}

void second_function(data_t *d)
{
printf(&quot;%s %d/%d/%d\n&quot;, d->message,d->month,
d->day,d->year);
}

 
hey :) thanks, i was going to post my code but i wasn't sure if that was okay in this forum. I was trying to pass and call the function with a variable as opposed to a pointer. That seems to be my main error.

thanks for the help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top