A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 5 years ago

Reading in line by line in C? I am having trouble with one programming problem: Write a complete program that reads in the player database of project 1 and prints out all the players who have made $6.0 millions or higher in the following format: Quarterback Donovan McNabb makes $12.00 millions - The file being read from is players.txt which is in the format like this 7869 QB Brees Drew 10.4 10 260. 3560 QB Brady Tom 9.6 11 240 The PROBLEM I am having is reading in these lines. I can attach my whole code, but the main section of my code is this: i=0; while(fscanf(players,"%d %c%c\n", &p

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

    i=0; while(fscanf(players,"%d %c%c\n", &playerID, &position[i], &position[i+1])){ printf("%d %c%c\n", playerID, position[i], position[i+1]); } //This only prints out 7869 QB I know this is very inefficient since you are reading in every character. So i tried to change the two %c%c to a string %s but i keep getting a segmentation error(core dumped). I read ppl using fgets and other stuff but I have to use fscanf etc I am lost and have no idea how to read in each line. I hope someone can help.Thanks!

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

    Are you sure, when you used "%s" instead of "%c%c" that you wrote "position" as parameter instead of "&position"?

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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...


  • 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.