From c09f50612d8d45261360ce849e82781c2278f820 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 12 Apr 2016 11:58:23 -0400 Subject: [PATCH] ex9 --- lcthw-remnants-2/.gitignore | 1 + lcthw-remnants-2/ex9.c | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 lcthw-remnants-2/ex9.c diff --git a/lcthw-remnants-2/.gitignore b/lcthw-remnants-2/.gitignore index f37cd25..f65443b 100644 --- a/lcthw-remnants-2/.gitignore +++ b/lcthw-remnants-2/.gitignore @@ -5,3 +5,4 @@ ex5 ex6 ex7 ex8 +ex9 diff --git a/lcthw-remnants-2/ex9.c b/lcthw-remnants-2/ex9.c new file mode 100644 index 0000000..f6b463c --- /dev/null +++ b/lcthw-remnants-2/ex9.c @@ -0,0 +1,52 @@ +#include + +int main(int argc, char *argv[]) +{ + int numbers[4] = {0}; + char name[4] = {'a'}; + + // first, print them out raw + printf("numbers: %d %d %d %d\n", + numbers[0], numbers[1], + numbers[2], numbers[3]); + + printf("name each: %c %c %c %c\n", + name[0], name[1], + name[2], name[3]); + + printf("name: %s\n", name); + + // setup the numbers + numbers[0] = 1; + numbers[1] = 2; + numbers[2] = 3; + numbers[3] = 4; + + // setup the name + name[0] = 'Z'; + name[1] = 'e'; + name[2] = 'd'; + name[3] = '\0'; + + // then print them out initialized + printf("numbers: %d %d %d %d\n", + numbers[0], numbers[1], + numbers[2], numbers[3]); + + printf("name each: %c %c %c %c\n", + name[0], name[1], + name[2], name[3]); + + // print the name like a string + printf("name: %s\n", name); + + // another way to use name; + char *another = "Zed"; + + printf("another: %s\n", another); + printf("another each: %c %c %c %c\n", + another[0], another[1], + another[2], another[3]); + + return 0; +}