-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex15.c
40 lines (29 loc) · 783 Bytes
/
ex15.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
void spacer(){
printf("---\n");
}
int main(int argc, char* argv[]){
int ages[] = {23, 43, 12, 89, 2};
char* names[] = {"Al", "frank", "Ma", "Jo", "Lisa"};
int count = sizeof(ages) / sizeof(int);
int i = 0;
char* template = "%s been around fo %d years\n";
for(i = 0; i < count; i++){
printf(template, names[i], ages[i]);
}
spacer();
int* cur_age = ages;
char** cur_name = names;
for(i = 0; i < count; i++){
printf(template, *(cur_name+i), *(cur_age+i));
}
spacer();
for(i = 0; i < count; i++){
printf(template, cur_name[i], cur_age[i]);
}
spacer();
for(cur_name = names, cur_age = ages; (cur_age - ages) < count; cur_name++, cur_age++){
printf(template, *cur_name, *cur_age);
}
return 0;
}