From 8ac30a239d26a374b8f422227dddf8049d501239 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 19 Apr 2024 20:53:48 -0400 Subject: [PATCH] Up through lcthw ex14 --- lcthw/.ex14.argv | 4 ++++ lcthw/.gitignore | 1 + lcthw/ex14.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 lcthw/.ex14.argv create mode 100644 lcthw/ex14.c diff --git a/lcthw/.ex14.argv b/lcthw/.ex14.argv new file mode 100644 index 0000000..c74db5b --- /dev/null +++ b/lcthw/.ex14.argv @@ -0,0 +1,4 @@ +eggs +legs +pegs +jegs diff --git a/lcthw/.gitignore b/lcthw/.gitignore index 29a77ad..8942676 100644 --- a/lcthw/.gitignore +++ b/lcthw/.gitignore @@ -7,3 +7,4 @@ ex10 ex11 ex12 ex13 +ex14 diff --git a/lcthw/ex14.c b/lcthw/ex14.c new file mode 100644 index 0000000..9cdfeee --- /dev/null +++ b/lcthw/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((int)ch) || isblank((int)ch); +} + +int main(int argc, char *argv[]) +{ + print_arguments(argc, argv); + return 0; +}