howdy everyone,
here's the question...I have a function that returns a pointer to a structure...now I'm trying to send that info into my main function by assigning it to a variable. So in main I have
Code:
`time trip = sum(&day1, &day2);`
Which doesn't work assumably because I can't assign a value of type pointer to struct to a fundamental type (correct?)...so I convert it to:
Code:
`time* trip = sum(&day1, &day2);`
Which also doesnt work, I'm assuming because if trip is a pointer I can't initialize it to the value of a function? I'm not sure why it doesn't work actually...and I was wondering if anyone had an answer for me...and also I was curious if it doesn't work for the second reason how would I make the variable trip accept a pointed to value?
Phew...thanks yet again -Chap

PS - If I'm not being clear at all...feel free to insult me

2. Code:
`time trip = *sum(&day1, &day2);`

3. ok...I found out what was wrong...I created this new pointer to accept the function return:
Code:
```time* p_trip;
p_trip = sum(&day1, &day2);
show_time(p_trip);```
Quick question...does this look like a reasonable solution? Obviously it works so it's A soluation...I was wondering if this isn't optimal...I'd hate to develop bad habits so early in my programming...-Chap

4. interesting code Salem...now what would the * before the sum function do to that function call? I'm very curious...thanks for the reply by the way...-Chap

5. Same as it does with
myint = *myintptr;

You have something which is a pointer, the * dereferences that pointer.

6. oh wow...i didnt know you could dereference a function call...that's awesome information salem...thanks!

7. Don't think of it as dereferencing a function call. Think of it as derefrencing the pointer that was returned by the function call. The whole line is like a 2 step processes.
1.) Call function. Function returns something.
2.) Assign what the function returned to the left value. You aren't assigning the "function", your assigning the thing returned by the function.

Hope that helps

PK

8. that's makes a lot more sense thanks