Can you do a fscanf inside of a for loop? for example: for(i=0;fscanf(input, "%c", &dummy) != EOF;i++)
yes
okay thanks! I will test it out in my program
Did it work?
yeah slightly...its in a larger program of mine so i think the i++ in the for loop is messing things up. I might have to keep it in a while loop instead
I took the i++ out and it works great now. Thanks again
Seems like a while loop would be more appropriate. You're not using a loop variable, so the for loop doesn't buy you anything. These loops are equivalent: for (a; b; c) ; a; while (b) c; Well, mostly equivalent. In some languages a variable declared in the "a" statement in the for loop won't survive past the for statement body. In the while loop it will. The for loop just gathers the a, b, and c statements together into one neat package so they're conceptually easier to process as a unit.
If you're sure that there's data, a do while construct may be the best choice: do { fscanf(); } while( !feof);
Join our real-time social learning platform and learn together with your friends!