Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8099967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:35:05+00:00 2026-06-05T22:35:05+00:00

why when using fscanf to acquire data from a file, is used 2 times,

  • 0

why when using fscanf to acquire data from a file, is used 2 times, once before the “!feof(fin)” and later, as shown in the code below:

fscanf(fin, "%s", letta);
while(!feof(fin)){

    fscanf(fin, "%s", letta);
}

the word read is not the same?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:35:08+00:00Added an answer on June 5, 2026 at 10:35 pm

    No the word read would not be the same since you read from the file twice, you would get different data each time.

    The condition in the while tests to see if you are at the end of file, in order to do that a read attempt must have been made, which requires the fscanf() before the loop.

    Once you are inside the loop you want to continue reading from the file. Presumably there would be more code inside the loop to process the data you are reading.

    In the code you have posted, if you encountered the end of file with your first read attempt, you wouldn’t enter the (while) loop.

    Contrast this with a do-while construct where the test is at the bottom of the loop (ie the read occurs only once, at the “bottom” of the loop). There you will always enter the loop at least once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get double values from file using fscanf function. I am
I'm used to using fscanf for simple file input, because it makes it simple.
I've already got some code to read a text file using fscanf() , and
I am trying to read a text file using fscanf.I am working in eclipse
I've got some analysis code ( myprog ) that sucks in data using the
I am attempting to parse a text (CSS) file using fscanf and pull out
I'm reading some data from a file. The format is stated tobe ASCII text
I am using fscanf to read a file which has lines like Number <-whitespace->
I need to read from a file from using C. #include <stdio.h> struct record{
I am parsing a text (css) file using fscanf. The basic goal is simple;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.