using strlen instead of null terminator

This commit is contained in:
Dan Buch 2011-09-18 10:40:21 -04:00
parent 20da5c59fd
commit c9de7b1c13

9
ex14.c
View File

@ -1,22 +1,23 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
void print_letters(char arg[]); void print_letters(char arg[], int nchars);
void print_arguments(int argc, char *argv[]) void print_arguments(int argc, char *argv[])
{ {
int i = 0; int i = 0;
for(i = 0; i < argc; i++) { for(i = 0; i < argc; i++) {
print_letters(argv[i]); print_letters(argv[i], strlen(argv[i]));
} }
} }
void print_letters(char arg[]) void print_letters(char arg[], int nchars)
{ {
int i = 0; int i = 0;
for (i = 0; arg[i] != '\0'; i++) { for (i = 0; i < nchars; i++) {
char ch = arg[i]; char ch = arg[i];
if(isalpha(ch) || isblank(ch)) { if(isalpha(ch) || isblank(ch)) {