Advertisement

raw file

Started by March 05, 2002 03:04 PM
1 comment, last by the origin 22 years, 11 months ago
hi i want to fill an array world[256][256] witht the brightness value of an raw file (each piont gives a value to his coordinates) the pixel 1,5 fills the array world[1][5]with his own brightness value may somebody send me the loading code or tipp ?? but please dont post "look at nehes tut ..." thanks
What language are you using? You should check a programming manual and learn how to manipulate files at the most basic level - as a programmer you'll need to know how to do that sooner or later. If you're talking about C/C++, it goes like this (assuming 1-byte raw values, integers):

#include <stdio.h>
int main(int argc, char **argv)
{
unsigned char world[256][256];
FILE * inputfile;
int arraypos;
inputfile = fopen("data.raw","rb");
if (inputfile)
for (arraypos=0;(arraypos<256*256)&& (feof(inputfile) == 0);arraypos++)
world[arraypos/256][arraypos%256]= (unsigned char) fgetc(inputfile);
return 0;
}

Edited by - Chromebender on March 5, 2002 5:49:10 PM
Advertisement
I would have done this:

  unsigned char world[256][256];FILE *file = fopen("world.dat","rb");if(file) {  if(fread (world, 256*256, 1, file)!=1)   {    // Load failed. Do something about it.   }  fclose(file); }  


But either way, close the file when you''re done with it!
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement