I have names of certain students and their ages stored in a text file
'records.txt'.

LIKE:

John 22
Paul 21
Sam 24
Harry 23


Now i want to store these ages and names in a structure 'records(r)' directly from the file. (Here i am not taking any input from the user)
as r.name & r.age.

Any clue to the solution???

Welcome Raza Najam.

Please read this rules:

Homework policy.

How to post your questions?

To solve your problem:
1. open data file in read mode.
2. Read data from the file and store it into structure variable.
3. Close the data file.

Show your code if you got any problem.

>Any clue to the solution???
Yes, start with the structure.

Here you wont get any help until you show some effort... Most of us here are students,and we too learn the same way...so stop chikening out and try!!! You will do it.

I find if somethings too complicated to do with little abstaction, make it more abstract. In C, that basicly means making more functions to do smaller tasks. I suprized myself what I can do with this technique. I reccomend making a function to seperate the words one by one, and make another function to put it into the struct. Good luck with your project:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.