![]() |
Records and Files
This topic is really new to me, i was just reading some stuff ahead of my class and saw a practisable question. However i have started it and stuck here. See question below.
QUESTION You are required to create a student management system that will allow you to store and update student records. Each student record should consist of an id, a name (fist name and last name), date of birth, address, telephone number and the program being pursued. Assume 10 records will be stored. 1. Create and populate an array of records. Store records into file 2. Allow user to update a record. Note, the user should only manipulate the data structure. All changes to the data structure should then be use to overwrite the file. 3. Allow user to search for a record from the data structure. 4. Print all records from the structure. NB. The students should create appropriate functions to solve the problem. Three Questionss 1. Why when it is printed i get rubbish? 2. When i search for the ID, how can i display the entire information for that ID? 3. Im lost to how i am suppose to update the file 4. Is the loading function done correctly PHP Code:
|
Re: Records and Files
Quote:
|
Re: Records and Files
Anyway I guess what you really wanted was some useful help.
> 1. Why when it is printed i get rubbish? When what is printed? What option did you choose? What output did you get and what output did you expect? Have you identified the line of code that prints wrong stuff? If the output is unprintable and you're using a Unix-style OS then redirect the output to a file and use od -x -c to display the output. Or just pipe the output to od -x -c, but sending it to a file gives you the option of keeping it around for future reference. What exactly does LoadStudents() do? Specifically the "a+" parameter of fopen? (Note I'm not asking because I don't know. I'm asking because I want *you*, Mr Smart Alec, to find the answer out for yourself) 2. When i search for the ID, how can i display the entire information for that ID? Maybe with printf()? Could there be something in SaveStudents() that you could use? (Look again if you think the answer to that is "no") 3. Im lost to how i am suppose to update the file Probably that will be the subject of a future lesson. Have a look at LoadStudents(). It seems to be missing a lot of stuff. Is it meant to read the file into a data structure? Typically what you do in a program is to read a file into some internal data structures, process the data, and if you need to update the file on disk then you would write the data structures back out to the file. So in effect you don't update the file directly. Since the data is not fixed length you don't have the option of using fseek and fwrite, so you'll have to overwrite the whole file from the data structures. 4. Is the loading function done correctly I've already alluded to one possible answer to that question. But what do you think? What should the function do? What does it actually do (hint: RTFM for fopen())? Do you think it might need to mirror SaveStudents()? |
Re: Records and Files
To be honest though I think a *better* use of your time would be to
(a) think up some variations on the exercises you've already been given; (b) see if you can help other students who are stuck; explaining stuff that you think you understand and fielding their questions is a great way to consolidate what you know and to learn new stuff. I learn new stuff all the time posting here; often a question will trigger some interest and I'll go off and look it up. And I'm not exactly new to this; I started programming in about 1981. |
| All times are GMT +5.5. The time now is 08:24. |