-2

im trying to scan (perhaps using fgets) 6 different strings from the same line in a file that is accessed by the program. i used the following struct to hold the 6 different strings:

struct _entry {
    char subject[10];
    char prof_name[10];
    char prof_surname[10];
    int period;
    int credits;
    int pass_rate;
};
struct _entry entry[MAX_LINES];

if someone could help me on what i can do to scan 1 line from a file, and it will be 3 strings and 3 digits that i can assign to each of the struct values.

1 Answers1

0

Read file line by line using -

  fgets() or getline 

( getline() is not portable. Its only for linux based application )

Parse line using -

   strtok or strtok_r or sscanf

Convert parsed string into Integer using-

    atoi
Rocoder
  • 1,083
  • 2
  • 15
  • 26