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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -