using strlen and strncpy to make copies of strings instead of just copying pointers, although the need for (char *) makes me think I don't have the right idea

This commit is contained in:
Dan Buch 2011-09-10 01:06:06 -04:00
parent de57b63f46
commit 7cb0c4aab5

12
ex11.c
View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
@ -21,11 +22,20 @@ int main(int argc, char *argv[])
}
i = 0;
size_t l;
while(i < num_states) {
states[i] = argv[i];
l = strlen((char *)&(argv[i]));
strncpy((char *)&(states[i]), (char *)&(argv[i]), l);
printf("copied %s into state %d\n", states[i], i);
i++;
}
i = 0;
while(i < num_states) {
printf("state %d: %s\n", i, states[i]);
i++;
}
return 0;
}