anyone can explain me, why this parts of code are acting differently?
while((c = fread(buf, sizeof(char), 1, f)) != 0);
{
if(write(t, buf, c) < 0)
{
return E_MSGSEND;
}
}
/////////////////////////////////////
do
{
c = fread(buf, sizeof(char), 1, f);
if(write(t, buf, c) < 0)
{
return E_MSGSEND;
}
} while(c != 0);
while {} runs only 1time but do {} while 5times. Whats is the difference? Before while {} c is intialized to 1.
Thanks an advice
You have a semicolon after your first
while:This in effect makes it an empty loop, which may well execute the same amount of times as the other loop, but its body doesn’t include any statements. The following
if, though, is not part of that loop anymore, so it only executes once.