0
Can anyone explain how this code work and execute
4 Answers
+ 5
Basically, it tests for an empty string.
text is a 2D array of characters. If the following where given:
text[t]="test";
*text[t] is the first 't'. Strings are ended with a '\0' or 0 byte. Booleans are true for non-zero values and false for zero. ! is the not unary operator. !*text[t] would be false for the string test above as 't' is true so !'t' is false. When text[t] is set to the empty string "", *text[t] is '\0' or false so !*text[t] is true.
+ 5
It could have also been written:
if(!text[t][0])
which would execute the exact same machine code. But, being 2 characters longer tends to be avoided even though it is so much clearer to other people.
+ 4
As coded, it doesn't. It generates a compile error. If modified by moving line 16 to after line 20, it will work. It will output a prompt: enter the empty line to quit. It counts the lines it reads so entering:
test
tes
te
t
gets 0 to 4 displayed. The strings get store in the array. Each of the characters in the strings gets a blank line outputted for it so 10 of them.
+ 1
John can you explain what is this meaning
if(!*text[t])