assigning back and forth between char arrays
This commit is contained in:
parent
2830ca4774
commit
947ce04319
24
ex10.c
24
ex10.c
@ -3,17 +3,31 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
printf("arg %d: %s\n", i, argv[i]);
|
||||
}
|
||||
|
||||
char *states[] = {
|
||||
"California", "Oregon",
|
||||
"Washington", "Texas"
|
||||
};
|
||||
int num_states = 4;
|
||||
|
||||
char *tmp = states[0];
|
||||
states[0] = argv[0];
|
||||
argv[0] = tmp;
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
printf("arg %d: %s\n", i, argv[i]);
|
||||
}
|
||||
|
||||
for(i = 0; i < num_states; i++) {
|
||||
printf("state %d: %s\n", i, states[i]);
|
||||
}
|
||||
|
||||
argv[0] = states[0];
|
||||
states[0] = tmp;
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
printf("arg %d: %s\n", i, argv[i]);
|
||||
}
|
||||
|
||||
for(i = 0; i < num_states; i++) {
|
||||
printf("state %d: %s\n", i, states[i]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user