From 32228957e45fc68f9d1b214d51a40d54fdc58902 Mon Sep 17 00:00:00 2001 From: RatRiot Date: Thu, 18 Oct 2018 21:26:47 -0500 Subject: [PATCH] It is better to announce we received a null pointer which is different from empty string. --- Chapter1/ex1-13-vertical.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Chapter1/ex1-13-vertical.c b/Chapter1/ex1-13-vertical.c index afea75a..eb58e2d 100644 --- a/Chapter1/ex1-13-vertical.c +++ b/Chapter1/ex1-13-vertical.c @@ -8,10 +8,11 @@ #define IN 1 #define OUT 0 -unsigned len(const char *); +int len(const char *); main() { + int word_count = 0; /* int c, state; state = OUT; @@ -31,12 +32,14 @@ main() printf("%s length is %d.\n", "Hello", len("Hello")); 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) - return 0; + return -1; int length = 0;