Can somebody kindly explain to me these 2 lines of code from th eposted code above that look simple but have a strange arrangement.
First time I come across this kind of condition settings :
if (inString [inCount] == EndMarker) break;
{
(++inCount < INLENGTH);
inString[inCount] = 0; // null terminate the string
}
Q1: what is the { doing after the "if (inString [inCount] == EndMarker) break;" since the if condition is completed in a single line with a "break;"
is it similar to an "else{".
Q2: what is the equivalent of: (++inCount < INLENGTH); in lame man's code?
Q1: what is the { doing after the "if (inString [inCount] == EndMarker) break;" since the if condition is completed in a single line with a "break;"
is it similar to an "else{".
C and C++ allow you to define blocks of code anywhere. Doing so does not have to make sense. In the snippet you posted, the curly braces define a useless block of code.
Q2: what is the equivalent of: (++inCount < INLENGTH); in lame man's code?
PaulS:
C and C++ allow you to define blocks of code anywhere. Doing so does not have to make sense. In the snippet you posted, the curly braces define a useless block of code.
Equivalent in what sense?
PaulS:
C and C++ allow you to define blocks of code anywhere. Doing so does not have to make sense. In the snippet you posted, the curly braces define a useless block of code.
Equivalent in what sense?
42;
is equivalent in that it accomplishes nothing.
Perhaps you meant to say "uselessly defines a block of code", as the code in the {} is not useless but blocking it is superfluous.
There are reasons to place curly braces around code other than to block for if/esle/for statements, you can worry about that later. Here it is harmless.
An "else" before that {block} in the OP's code would not change the interpretation and would make it a bit clearer maybe.
Calling
(++inCount < INLENGTH);
equivalent to
42;
we'll just have to chalk up to the breakfast effect - posting before proper nutrients have been delivered to the brain.
In "lame man's code", the line in question boils down to
++inCount;
It increments inCount. If we assume inCount is an integer, that means it adds one.