delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/09/16:54:30

Message-ID: <2FFF738A.74A4@linetap.com>
From: nebo <nebo AT linetap DOT com>
Organization: neboland
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Writing to a file.
References: <01bdaac9$dbe7ec80$bf0562cb AT default>
Lines: 43
Date: Thu, 09 Jul 1998 03:04:30 GMT
NNTP-Posting-Host: 209.205.49.227
NNTP-Posting-Date: Wed, 08 Jul 1998 23:04:30 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Oliver Batchelor wrote:
> 
> Hello,
> I am writing a map editor for a game I am making A rts game with tiles.
> I have a big array of tiles.
> 
> eg. unsigned char map[100][100]
> 
> I have done the editing part. All I need now is to save the array into a
> file.
> 
> Can anyone tell me how I would dump the array to a binary file ??
> 
> thanks,
> 
> Oliver Batchelor


 FILE *map_file;
 map_file = fopen("FILE.DAT", "wb");
 fwrite((char*) &map, sizeof(map), 1, map_file);
 fclose(map_file);
 //Will write sizeof(map) bytes to the given file

 map_file = fopen("FILE.DAT", "rb");
 fread((char*)&map, sizeof(map), 1, map_file);
 fclose(map_file);
 //Will read sizeof(map) bytes from the file filling map[][]
 
 
-- 



        Nb
        nebo AT LTS                MajorNet
        nebo AT linetap DOT com        Internet


        I'll stop drinking when I can't pour,
        I'll stop standing when I fall over,
        I'll stop moving when I pass out,
        I'll stop dreaming when I die.

- Raw text -


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