It is better to announce we received a null pointer which is different from empty string.
This commit is contained in:
parent
206419468d
commit
32228957e4
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue