delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/27/18:09:43

From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Boy do I feel STUPID!! ....Files question...
Date: 24 Aug 1997 08:39:53 GMT
Organization: The National Capital FreeNet
Lines: 36
Message-ID: <5tos0p$pdf@freenet-news.carleton.ca>
References: <01bcaf81$9b31b7a0$812042d1 AT ghema DOT jaguarsystems DOT com>
Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
NNTP-Posting-Host: freenet6.carleton.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"Locke" (lockeg AT usa DOT net) writes:
> Hey everyone,
> 
> i am feeling really stupid, but i need help.  I have been working on this
> game and it's going verrry well, but i've hit a wall.  I can't believe
> this, but i can't remember how to write an array of structures to a file!
> 
> for instance... say i have a structure called S_MAP it goes as follows:
> 
> typedef struct
> {
>    char *name;
>    int tiles[MAX_Y][MAX_X];
> } S_MAP;
> 
> S_MAP Maps[MAX_MAPS];
> 
> 
> That's a very watered down version of the structure, but it gets the idea
> across...
> Anyway, i want to write the variable Maps to a file and then later read it
> back in.  I can't believe that I can write low level graphics routines, a
> keyboard handler and all this really complicated stuff, but can't remember
> how to write to a file.  Well, any help would be greatly appreceated...

fwrite(Maps,sizeof(S_MAP),MAX_MAPS,my_file_pointer_returned_by_fopen);

Two remarks: one: this is documented in the info files, info libc a
fwrite. Two, this is a general C question, and might be better placed in
comp.lang.c.
--
    .*.  Where feelings are concerned, answers are rarely simple [GeneDeWeese]
 -()  <  When I go to the theater, I always go straight to the "bag and mix"
    `*'  bulk candy section...because variety is the spice of life... [me]
Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019