My unit doesn't teach this so I am unaware about the correct syntax to go about what I want to do. I have hit google but have produced no answers to my specific problem. So here we go.

I have a series of nested structs.

Is this possible that instead of typing - program.week[0].workout[0].exercise[0].exerciseName
everytime I want to access an element.
That I can access the elements of the most nested struct via a pointer.

Eg.

clientProgram *prtToWorkout;
prtToWorkout = &(myProgram.week[0].workout[wkOut]);

PopulateWorkout(&prtToWorkout, numberOfExercises); //Funct call

void PopulateWorkout(clientProgram *prtToWorkout, int numOfEx)
{
    printf("Enter program grouping letter eg. A: ");
    scanf("%c%*c", &(*prtToWorkout)->programName.exercise[ex_num].exerciseName);
}

Hope you guys can help shine some light on this one for me..

Regards,
Nate

Edited 7 Years Ago by nateuni: n/a

Oops, misunderstood your problem.

This post can be deleted.

Edited 7 Years Ago by wheel: n/a

Is this possible that instead of typing - program.week[0].workout[0].exercise[0].exerciseName
everytime I want to access an element.
That I can access the elements of the most nested struct via a pointer.

Yes. If you have an object, you can have a pointer to it:

#include <stdio.h>

struct A
{
    struct B
    {
        struct C
        {
            int dat;
        } c;
    } b;
};

int main()
{
    struct A a;
    struct C* pc = &a.b.c;

    pc->dat = 123;
    printf("through struct pointer: %d\n", pc->dat);
    printf("direct access:          %d\n", a.b.c.dat);

    return 0;
}

Is that what you were trying to do?

I haven't got a chance to try it before going to bed.. (and I don't want to be half asleep having coding dreams, like when I code to late in the evening).

BUT it looks like exactly the clarification I was looking for. Thanks heaps.. your reply was simple and effective. Seriously I really appreciate it.

Regards,
Nate

This question has already been answered. Start a new discussion instead.