Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Empty-string/C/empty-string.c
Normal file
19
Task/Empty-string/C/empty-string.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <string.h>
|
||||
|
||||
/* ... */
|
||||
|
||||
/* assign an empty string */
|
||||
const char *str = "";
|
||||
|
||||
/* to test a null string */
|
||||
if (str) { ... }
|
||||
|
||||
/* to test if string is empty */
|
||||
if (str[0] == '\0') { ... }
|
||||
|
||||
/* or equivalently use strlen function
|
||||
strlen will seg fault on NULL pointer, so check first */
|
||||
if ( (str == NULL) || (strlen(str) == 0)) { ... }
|
||||
|
||||
/* or compare to a known empty string, same thing. "== 0" means strings are equal */
|
||||
if (strcmp(str, "") == 0) { ... }
|
||||
Loading…
Add table
Add a link
Reference in a new issue