I have a struct
typedef struct
{
my ints
and char's
} structname;
in my server .c file inside main()
structname Header;
I’m calling the function(Header);
which looks at another .c file
And populates the header with e.g. strcpy(Header.Name1,pch);
Which gets populated correctly as i have used gdb to debug it
(gdb) p Header.Name1
$5 = "Bilka\000\332\326\377\177\000\000\001\000\000\000\000\000\000\000\b]\022\"E\177\000\000p\356\332\326\377\177\000\000\034\000\000\000\000\000\000\000\t\000\000\000\000"
After this function ends and returns TRUE it goes back to the next line on the server.c but if i do a print on Header.Name1 i’m getting a blank header what could be the reason.
Function arguments in C are passed by value. So if your function’s signature looks like this:
It means that the argument is copied when the function is called. You then modify that temporary copy inside the function, but that doesn’t change the original object. You might want to pass a pointer to your struct to the function instead: