char word[5]={"fayed"};
word[1]=NUL;
printf("%s",word);
It shows error ... and NUL
to be undeclared.
char word[5]={"fayed"};
word[1]=NUL;
printf("%s",word);
It shows error ... and NUL
to be undeclared.
No, there is no standard identifier called NUL
. If you want to null-terminate a string, use 0
or '\0'
.
For completeness, it is worth noting that the null pointer is spelt NULL
. See If NULL
and 0
are equivalent as null pointer constants, which should I use?
You are referring to NUL, the ASCII character.
The C standard does not mandate ASCII encoding for characters, but it does use the character value 0 to terminate strings (one common meaning of NUL in ASCII).
Just use 0
:
word[1]=0;
And make sure not to confuse it with the character '0'
.