Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

tdabboud

  • 3 years ago

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

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

    yes

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

    okay thanks! I will test it out in my program

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

    Did it work?

  4. tdabboud
    • 3 years ago
    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

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

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

  6. dmancine
    • 3 years ago
    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.

  7. rsmith6559
    • 3 years ago
    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);

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.