From b979a794d6a993b39ad7b46d2dd53b1ce1d5b2fb Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 19 Apr 2024 21:22:10 -0400 Subject: [PATCH] lcthw ex14 extra credit --- lcthw/ex14.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lcthw/ex14.c b/lcthw/ex14.c index 9cdfeee..a7e1dca 100644 --- a/lcthw/ex14.c +++ b/lcthw/ex14.c @@ -1,27 +1,27 @@ #include #include +#include // forward declarations -int can_print_it(char ch); -void print_letters(char arg[]); +void print_letters(size_t len, char arg[]); void print_arguments(int argc, char *argv[]) { int i = 0; for (i = 0; i < argc; i++) { - print_letters(argv[i]); + print_letters(strlen(argv[i]), argv[i]); } } -void print_letters(char arg[]) +void print_letters(size_t len, char arg[]) { int i = 0; - for (i = 0; arg[i] != '\0'; i++) { + for (i = 0; i < len; i++) { char ch = arg[i]; - if (can_print_it(ch)) { + if (isprint((int)ch)) { printf("'%c' == %d ", ch, ch); } } @@ -29,11 +29,6 @@ void print_letters(char arg[]) 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);