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

  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,336
    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,336
    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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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,336
    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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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