Consider this code:
char *strs[] = { "string1", "string2", NULL };
char *ptr1 = NULL, *ptr2 = NULL, *tmp;
short iter = 0;
tmp = ptr1;
while (iter < 2)
{
tmp = strdup(strs[iter]);
tmp = ptr2;
iter++;
}
printf("1: %s\n2: %s\n", ptr1, ptr2);
I want this to output "string1\nstring2\n" however str1 and str2 remain null. What am I doing wrong?