reading a textfile and storing the information into a structure array?

This is a discussion on reading a textfile and storing the information into a structure array? within the C Programming forums, part of the General Programming Boards category; say I have a text file that follows the format: student last name student number student grade for example: smith ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    20

    reading a textfile and storing the information into a structure array?

    say I have a text file that follows the format:

    student last name student number student grade

    for example:

    smith 17892 82
    peterson 12891 79
    mcdonald 97022 93

    and so on, and i want to read the text file that contains this data and then store it into structure array with data types

    char student_name
    char student_id
    int student_grade

    how can I do this? thanks.

  2. #2
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    Well, what part is stumping you or have you done nothing?

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    And the problem is what exactly? (Reading? Reading from a file? Storing a string into a char array?) And I guarantee you that student_name and student_id are not of type char.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    20
    i've created the structure lol. i dont know how to read or store though :|.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you know how you would do it if people were typing at the keyboard vs. reading from a file?

  6. #6
    Registered User
    Join Date
    Jul 2008
    Posts
    20
    yeah I do.

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    I think tabstop is saying show us how you would do it in the case of someone sitting and typing it in, and we'll go from there.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by rags_to_riches View Post
    I think tabstop is saying show us how you would do it in the case of someone sitting and typing it in, and we'll go from there.
    Especially since the difference between the two consists mainly of the letter "f".

  9. #9
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Yes indeed

  10. #10
    Registered User
    Join Date
    Jul 2008
    Posts
    20
    i got it guys, i found out how to use the fopen fscan stuff and its cool now. thanks anyway.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21