Up through lcthw ex14

This commit is contained in:
Dan Buch 2024-04-19 20:53:48 -04:00
parent d4b5c737e5
commit 8ac30a239d
Signed by: meatballhat
GPG Key ID: A12F782281063434
3 changed files with 46 additions and 0 deletions

4
lcthw/.ex14.argv Normal file
View File

@ -0,0 +1,4 @@
eggs
legs
pegs
jegs

1
lcthw/.gitignore vendored
View File

@ -7,3 +7,4 @@ ex10
ex11
ex12
ex13
ex14

41
lcthw/ex14.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdio.h>
#include <ctype.h>
// 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;
}