c - How to output a string, the result is (null)? -


this question has answer here:

how output pointer string, print result "(null)" outputting char?

printf("%s\n", *str ? str : "(null)"); 

if first character pointed str '\0', above print (null). otherwise, print string pointed str.

to handle case:

char *str = null; 

...use:

printf("%s\n", (str && *str)?str:"(null)"); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -