It is better to announce we received a null pointer which is different from empty string.

This commit is contained in:
RatRiot 2018-10-18 21:26:47 -05:00
parent 206419468d
commit 32228957e4
1 changed files with 6 additions and 3 deletions

View File

@ -8,10 +8,11 @@
#define IN 1 #define IN 1
#define OUT 0 #define OUT 0
unsigned len(const char *); int len(const char *);
main() main()
{ {
int word_count = 0;
/* /*
int c, state; int c, state;
state = OUT; state = OUT;
@ -31,12 +32,14 @@ main()
printf("%s length is %d.\n", "Hello", len("Hello")); printf("%s length is %d.\n", "Hello", len("Hello"));
printf("%s length is %d.\n", "", len("")); printf("%s length is %d.\n", "", len(""));
printf("%s length is %d.\n", NULL, len(NULL));
} }
unsigned len(const char *str)
int len(const char *str)
{ {
if (str == NULL) if (str == NULL)
return 0; return -1;
int length = 0; int length = 0;