From 7cb0c4aab58d94bde8f84284eca3ba1760103ddd Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 10 Sep 2011 01:06:06 -0400 Subject: [PATCH] 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 --- ex11.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ex11.c b/ex11.c index 7ff7988..eb4155d 100644 --- a/ex11.c +++ b/ex11.c @@ -1,4 +1,5 @@ #include +#include 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; }