I'm using C for a class project for the first time after first learning C++, so syntax is killing me... Basically, I need to store a string given by a function into a separate variable for later use.
I have an array of chars declared like this
char foo[];
A function that I'm given assigns a bunch of characters into this array (or pointers to characters?). I can print out the actual string stored in foo like this
printf("%s", foo);
And I can store its address in a different variable like this
char *bar;
bar = &foo[0];
printf("%s", foo);
The full string is output just fine in both cases. However, how can I store this string in a different variable? If foo changes, then bar will no longer hold the string I need since it is just pointing to foo. Anything I have thought of gives me compiler errors like
warning: initialization makes pointer from integer without a cast
Hopefully that's enough info. Thanks for the help in advance.