Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

tdabboud

Can you do a fscanf inside of a for loop? for example: for(i=0;fscanf(input, "%c", &dummy) != EOF;i++)

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 0

    yes

    • 2 years ago
  2. tdabboud
    Best Response
    You've already chosen the best response.
    Medals 0

    okay thanks! I will test it out in my program

    • 2 years ago
  3. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 0

    Did it work?

    • 2 years ago
  4. tdabboud
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • 2 years ago
  5. tdabboud
    Best Response
    You've already chosen the best response.
    Medals 0

    I took the i++ out and it works great now. Thanks again

    • 2 years ago
  6. dmancine
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • 2 years ago
  7. rsmith6559
    Best Response
    You've already chosen the best response.
    Medals 0

    If you're sure that there's data, a do while construct may be the best choice: do { fscanf(); } while( !feof);

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.