From 9158c349b31acfaa4b5a399215a65ba3715d8e89 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 18 Sep 2011 13:30:03 -0400 Subject: [PATCH] first version of exercise 15 --- ex15.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ex15.c diff --git a/ex15.c b/ex15.c new file mode 100644 index 0000000..c890f92 --- /dev/null +++ b/ex15.c @@ -0,0 +1,47 @@ +#include + +int main(int argc, char *argv[]) +{ + int ages[] = {23, 43, 12, 89, 2}; + char *names[] = { + "Alan", "Frank", + "Mary", "John", "Lisa" + }; + + int count = sizeof(ages) / sizeof(int); + int i = 0; + + for(i = 0; i < count; i++) { + printf("%s has %d years alive.\n", + names[i], ages[i]); + } + + printf("---\n"); + + int *cur_age = ages; + char **cur_name = names; + + for(i = 0; i < count; i++) { + printf("%s is %d years old.\n", + *(cur_name+i), *(cur_age+i)); + } + + printf("---\n"); + + for(i = 0; i < count; i++) { + printf("%s is %d years old again.\n", + cur_name[i], cur_age[i]); + } + + printf("---\n"); + + for(cur_name = names, cur_age = ages; + (cur_age - ages) < count; + cur_name++, cur_age++) + { + printf("%s lived %d years so far.\n", + *cur_name, *cur_age); + } + + return 0; +}