Did I do this right?

For EX14, I was supposed to get rid of the can_print_it function so I came up with this solution using !isdigit

void print_letters(char arg[]) 
{
	int i = 0;
	for(i = 0; arg[i] != '\0'; i++) {
		char ch = arg[i];
		if(!isdigit(ch)) {
			printf("'%c' == %d ", ch, ch);
		}
	}
	printf("\n");
}

Also figured out the second part of the extra credit, determining how long each argument is using strlen().

void print_arguments(int argc, char *argv[]) 
{
	int i = 0;
	
	for(i = 0; i < argc; i++) {
		unsigned long word_length = strlen(argv[i]);
		print_letters(argv[i]);
		printf("Argument %d is %lu character's in length.\n", i, word_length);
	}
}

Hi, Aby,

If you pass a punctuation char it will print it.

Okay, so I have some work to do or a new method to use.

Well, doing the same thing right now , since I skipped this extra when I did ex14, thx for bringing it back.
This will be awesome to redo!

I think you’re very close. Read the man page on isdigit to confirm it does what you think it does.

Got it…

1 Like

I also removed isidigit() in the final code.

EDIT: I found a bug. When I add numbers on to a word, it removes them, but doesn’t remove the length of the word with numbers in the output, so I will fix that.

1 Like

@abbyrjones72 I just did:


void print_letters(char arg[])
{
    int i = 0;

    for (i = 0; arg[i] != '\0'; i++) {
        char ch = arg[i];

        if (isalpha(ch) || isblank(ch)) {
            printf("'%c' == %d ", ch, ch);
        }
    }

    printf("\n");
}

I basically pulled that function inside this one. And of course I read man.

1 Like