This function is supposed to search through a text file for the new line character. When it finds the newline character, it increments the newLine
counter, and when
Dry ran the code:
If file starts with a newline character and newLine
is 1
:
For the first iteration:
if (c == '\n') //Will be evaluated as true for a new-line character.
{
newLine++; //newLine becomes 2 before next if condition is evaluated.
if (newLine < 2) //False, since newLine is not less than 2, but equal.
{
printf("new line");
putchar(c);
}
}
else //Not entered
{
putchar(c);
newLine = 0;
}
On the second iteration: (Assume that it is a consecutive newline char case)
if (c == '\n') //Will be evaluated as true for a new-line character.
{
newLine++; //newLine becomes 3 before next if condition is evaluated.
if (newLine < 2) //False, since newLine is greater than 2.
{
printf("new line");
putchar(c);
}
}
else //Not entered
{
putchar(c);
newLine = 0;
}
So,
newLine
to 0
.