From 14c02e27c42af721230204acf8c9a20b6ca6366f Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 12 Apr 2016 14:17:07 -0400 Subject: [PATCH] ex14 --- lcthw-remnants-2/.gitignore | 1 + lcthw-remnants-2/ex14.c | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lcthw-remnants-2/ex14.c diff --git a/lcthw-remnants-2/.gitignore b/lcthw-remnants-2/.gitignore index deb26c7..45cf7ff 100644 --- a/lcthw-remnants-2/.gitignore +++ b/lcthw-remnants-2/.gitignore @@ -11,3 +11,4 @@ ex10 ex11 ex12 ex13 +ex14 diff --git a/lcthw-remnants-2/ex14.c b/lcthw-remnants-2/ex14.c new file mode 100644 index 0000000..9b4194a --- /dev/null +++ b/lcthw-remnants-2/ex14.c @@ -0,0 +1,41 @@ +#include +#include + +// forward declarations +int can_print_it(char ch); +void print_letters(char arg[]); + +void print_arguments(int argc, char *argv[]) +{ + int i = 0; + + for(i = 0; i < argc; i++) { + print_letters(argv[i]); + } +} + +void print_letters(char arg[]) +{ + int i = 0; + + for(i = 0; arg[i] != '\0'; i++) { + char ch = arg[i]; + + if(can_print_it(ch)) { + printf("'%c' == %d ", ch, ch); + } + } + + printf("\n"); +} + +int can_print_it(char ch) +{ + return isalpha(ch) || isblank(ch); +} + +int main(int argc, char *argv[]) +{ + print_arguments(argc, argv); + return 0; +}