September 11th, 2003, 08:23 PM
How do I get a structure member out of a pointer?
Being a novice in C I have lot of question here is one of them and it is in the bugbear of C beginners that is Pointers:
I have the function signature:
float timer(struct timespec* ts1)
struct tm startT;
startT = *(localtime ((time_t *) &(start.tv_sec)));
When I compile this I get an error because the method localtime in Time.h expects a timespec structure itself and NOT A POINTER to the timespec structure. Which brings me to the simple question how can I get access to the variable I am behind (start.tv_sec, which is a member of the structure) using the pointer that I have. I want to avoid passing in the structure itself.
Your input is appreciated.
September 12th, 2003, 02:04 AM
try something like
tm *pTime=NULL;//pointer to a tm struct
time_t SysTime;//an actual instance of the struc
//get the time
time(&SysTime);// the & sends in a pointer to our struct
//convert to local
//to look at an element of our struct pointer use the -> not .
Last edited by TechNoFear; September 12th, 2003 at 02:07 AM.
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.