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 5933541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:59:15+00:00 2026-05-22T14:59:15+00:00

I have a file that is organized line by line and the structure of

  • 0

I have a file that is organized line by line and the structure of all lines was defined by me but the contents of each line can increase or decrease according to two variables that the same line contains.

Line Example: 1 Andre 2 0 5 13 05 2011 4 13 05 2011

‘1’ represents the user ID

‘Andre’ represents the name associated to the ID

‘2 0’ subdivides: ‘2’ represents how many movies the user as taken home AND ‘0’ represents how many movies reservations the user has.

So far the line is following the pattern %d %s %d %d and they can be stored in the variables I want.

Now the hard part comes. Depending on the ‘2 0’ part, the program knows that has to read the pattern %d %d %d %d (‘5 13 05 2011’ and ‘4 13 05 2011’ – represent dates of movies taken home) 2 times and also the program knows that after reading 2 times the previous pattern it knows that i doesn’t need to read anything else due to the zero part in ‘2 0’.

Example of line with more data: 1 Andre 2 1 5 13 05 2011 4 13 05 2011 7 14 05 2011

‘2 1’

The ‘2’ part tells the program that in that line it should read ‘5 13 05 2011’ and ‘4 13 05 2011’ to variable_one[i][4] (example)

The ‘1’ part tells the program that in that line it should read ‘7 14 05 2011’ to variable_two[i][4] (example)

I’m using fscanf(file, "%d %s %d %d", &id[i],&nomes[i],&livros_num[i][0],&livros_num[i][1]); to read ‘1 Andre 2 0’ but how can i read the rest of the line according to ‘2 0’?

  • 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-05-22T14:59:16+00:00Added an answer on May 22, 2026 at 2:59 pm

    After your first call of fscanf, you need to loop depending on the variables you read. You seem to have already realized that the int‘s you read in your first call determine the number of extra reads you need in the line.

    int i;
    for ( i=0; i< livros_num[i][0]; i++ ) {
        int something, day, month, year; // 'something' is unclear to me in your code
        fscanf( file, "%d %d %d %d", &something, &day, &month, &year );
        // store these variables wherever
    }
    
    // same procedure for second number
    for ( i=0; i< livros_num[i][1]; i++ ) {
        int something, day, month, year; // 'something' is unclear to me in your code
        fscanf( file, "%d %d %d %d", &something, &day, &month, &year );
        // store these variables wherever
    }
    fscanf( file, "%s\n" ); // I'm NOT sure if this is nessecary, to move the file to the next line
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that can be any thing like ZIP, RAR, txt, CSV,
I have a file that I need to parse into an array but I
I have a txt file, where each line starts with participant No, followed by
I have a file that is organized into columns, with data that needs to
So, I have a text file that is organized like this <username>:<fullname>:<usergroups> I need
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus
I have a file that contains this <!-- CordovaVersion --> I want to replace
I have a file that looks like: 1 1 C C 1.9873 2.347 3.88776
I have a file that has the following format: 12345 TAB_HERE Name : The
I have a file that I want to import into Microsoft Dynamics CRM 2011

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.