box-o-sand/ex11.c

42 lines
758 B
C
Raw Normal View History

2011-09-10 04:22:25 +00:00
#include <stdio.h>
#include <string.h>
2011-09-10 04:22:25 +00:00
int main(int argc, char *argv[])
{
2011-09-10 04:27:04 +00:00
int i = 0;
while(i < argc) {
printf("arg %d: %s\n", i, argv[i]);
i++;
2011-09-10 04:22:25 +00:00
}
char *states[] = {
"California", "Oregon",
"Washington", "Texas"
};
int num_states = 4;
i = 0;
while(i < num_states) {
printf("state %d: %s\n", i, states[i]);
i++;
}
2011-09-10 04:29:54 +00:00
i = 0;
size_t l;
2011-09-10 04:29:54 +00:00
while(i < num_states) {
l = strlen((char *)&(argv[i]));
strncpy((char *)&(states[i]), (char *)&(argv[i]), l);
2011-09-10 04:33:57 +00:00
printf("copied %s into state %d\n", states[i], i);
2011-09-10 04:29:54 +00:00
i++;
}
i = 0;
while(i < num_states) {
printf("state %d: %s\n", i, states[i]);
i++;
}
2011-09-10 04:22:25 +00:00
return 0;
}