i am working through a fundamental C book and i thought i understood for loops but this has me completely stumped. maybe someone here can explain the difference of the below snippets of code.
andCode:int c = 0; int i = 0; for (c = getchar(); c != EOF;) { if (c == ' ') i++; } printf("%d", i);
they both compile and execute but the first one will not exit when i press ctrl + d and give the print out. the second one will work just fine giving the print out i want.Code:int c; int i = 0; for ( c = 0; (c = getchar()) != EOF;) { if(c == ' ') i++; } printf("%d", i);
the only difference i can see is in the for loops but they are the same, right? obviously not but i can't see how. can someone please explain the difference here?