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

  • Home
  • SEARCH
  • 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 3229874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:51:41+00:00 2026-05-17T16:51:41+00:00

I am trying to write a program that will read the existing records of

  • 0

I am trying to write a program that will read the existing records of a file and then index them in another file. The records are stored in the file named “players.bin” which is CSV format each record contains (username,lastname,firstname,numwins,numlosses,numties and i want to index them in a new file named “players.idx”. However the players.idx file will only contain a sequence of pairs of , where username is player’s user name and seq# is the sequence number of the player’s record stored in in the player file.

Here is what I have come up with so far:

 fd = open("players.bin", O_WRONLY | O_CREAT |
        O_APPEND, S_IRWXU);
 if (fd > 0) {
    //Read the contents of the file (if any)
    //and then print out each record until the end of file
    while (num = read(fd, &plyr, sizeof (plyr)) != 0) {
        printf("%s, %s, %s, %d, %d, %d\n\n", plyr.user_name,
                plyr.last_name, plyr.first_name, plyr.num_wins,
                plyr.num_losses, plyr.num_ties);
    }
    close(fd);
}

fd2 = open("players.idx", O_WRONLY | O_CREAT |
        O_APPEND, S_IRWXU);
if (fd > 0) {
    while (num = read(fd, &plyr, sizeof (plyr)) != 0) {   
        num = write(NOT SURE WHAT TO PUT HERE);
        record_count++;  //I am going to use this to keep track of seq numbers
    }
    close(fd2);
}

I am just really confused on how to go about this…Thanks

  • 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-17T16:51:41+00:00Added an answer on May 17, 2026 at 4:51 pm

    Look for a book/tutorial on opening, reading and writing files in C. It’s fairly easy, and once you know how to do it, it’s just a matter of opening one file for reading, and another one for writing.

    I’m sorry I’m not more specific, but to explain in detail I’d have to write a loong answer that still would do you less good than reading a book on the subject, or a tutorial.

    After you have a firm grip on that, take a look at fscanf and fprintf, those two functions will help you parse and write your index easily.

    edit: I really recommend not skipping the book/tutorial part. You’re opening your files wrong, and I suspect you’re reading the .bin erroneously too, though I’d have to see the rest of your program to be sure.

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

Sidebar

Related Questions

Hey there. I'm trying to write a small program that will read the four
I am trying to write a fragment program that will take a texture and
I am writing a C program that will read and write from/to a serial
I'm trying to write a program in Scala, that will accept SOAP-requests, get the
I'm trying to write a program that will change a particular GUID in a
I am trying to write a program that will, when executed, will go through
I'm trying to write a program that uses sockets to connect with other instances
I am trying to write a C++ program that takes the following inputs from
I'm trying to write a program in C (on Linux) that loops until the
I'm trying to write a resolution selection dialog that pops up when a program

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.