Jump to content

[C]Problems with reading input

- - - - -

  • Please log in to reply
3 replies to this topic

#1
your_rock

your_rock

    Newbie

  • Members
  • Pip
  • 8 posts
Hello,

I have a problem with reading input. I'm supposed to read team names from an input file, but I'm having a problem with reading teams with 2 names. For example, input is like this:

MNU ManchesterUnited A
BAR Barcelona A
RMA Real Madrid B
OL Lyon A
GLA Glasgow Rangers B

Group names come after the team names. I try to read them with

fscanf(filePtr, "%s %s %c", teams[x].teamAbbr, teams[x].teamName, teams[x].group);

this, but if a team has 2 names(like Manchester United), it reads only Manchester with %s, then %c gets a character from United... Any solutions?

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
You could read whole line and then split it; teamAbbr is always at start, team group is always last and everything in between is team name.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
your_rock

your_rock

    Newbie

  • Members
  • Pip
  • 8 posts

Flying Dutchman said:

You could read whole line and then split it; teamAbbr is always at start, team group is always last and everything in between is team name.

Can you please give an example?

#4
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
On this site, there's an example below. strtok could help you with splitting.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users