Passing structure by reference through 4 functions
Hi there,
I have the following code, listed below. Basically I need to pass a structure by reference through 4 functions so that I can change its value in the fourth function and then keep the changed value up to the top.
The following code is not working (C, Linux). Any help on that would be greatly appreciated.
Code:
#include "main.h"
void f1(struct list_type **info)
{
(*info)->type = 1;
strcpy((*info)->data, "1");
f2(&(*info));
}
void f2(struct list_type ***info)
{
(**info)->type = 2;
strcpy((**info)->data, "2");
f3(&(**info));
}
void f3(struct list_type ****info)
{
(***info)->type = 3;
strcpy((***info)->data, "3");
f4(&(***info));
}
void f4(struct list_type *****info)
{
(****info)->type = 4;
strcpy((****info)->data, "4");
}
int main(int argc, char **argv)
{
struct list_type *info = NULL;
info->data = malloc(sizeof(char) * 100);
if (info->data == NULL)
return 1;
info->type = 0;
strcpy(info->data, "0");
f1(&info);
free(info->data);
return 0;
}
Thank you very much.
Regards,
Nick