Re: fread fwrite struct
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 07:47:03 +0200
janssenssimon@xxxxxxxxxxx schrieb:
The code given is but a piece of complete code
All the nececary includes are included
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
witch also have such functions as clrscr() and gotoxy()
<conio.h> and <windows.h> are not standard C -- my compiler
and library combination just does not have them.
The thing I am trying to achief with this code toonhighscores is:
printf of a structure under the titles Naam, Score, Veld
After first having read it from a file.
And the thing I'm trying to achief with the code schrijfweg_highscores
is:
reading a existing binairy file into a structure (linked list).
adding one structure to the linked list
and writing the entire linked list to the overwritten file high.bin
Thank you, this confirms my guesses.
The problem I'm having with this piece of code is:
The first time I run the program, everything works, the reading, the
writing, adding, everything
but if you then close the program, and reopen it, non of the 2 function
work
while I don't see what the difference is with the first the program
runs,...
I actually answered the question: Your problem is that you store
pointers/addresses (HIGH.naam) in a file. As soon as your programme
terminates, these are no longer valid. If you restart the programme and
read in the addresses, there probably is not the same content in the
old location -- worse still, you access memory that does not belong
to your programme. You must store what the pointer points to, the
actual _content_. In this case, a string.
Thus the suggestion to switch from storing your stuff as binary to
storing it as text in a text file -- this can easily be inspected
and errors can be found.
If you want me to sent entire source of the project, please say so,...
No, this is not necessary for _this_ problem.
If you have further problems, try to reduce the version of your
programme you post here to the absolute minimum that still shows
the problem and compiles.
Please quote enough context so that other people know what is
going on -- this gives them a better chance to help you, too.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.
- References:
- fread fwrite struct
- From: janssenssimon@xxxxxxxxxxx
- Re: fread fwrite struct
- From: Michael Mair
- Re: fread fwrite struct
- From: janssenssimon@xxxxxxxxxxx
- fread fwrite struct
- Prev by Date: How to Define High-precision Date type
- Next by Date: Re: How to define an array of struct nested within a struct?
- Previous by thread: Re: fread fwrite struct
- Next by thread: gui design
- Index(es):
Relevant Pages
|