FILE *fp;
fp = fopen("demo1.bsp", "rb");
if(fp!=NULL)
{
char *ibsp;
fread((char *)&ibsp, 4, 1, fp);
if(strcmp(ibsp,"IBSP")!=0)
{
fclose(fp);
return false;
}
fclose(fp);
return true;
}
but that always returns false...any help?
and info on binary files in general? on quake 2 stuff?
Reading from a Binary File
I''m trying to load a Quake2 map file but i''m not getting very far. The first 4 bytes of the file are "IBSP", so i try to do this:
Well, you might want to change your declaration of ibsp to->
char ibsp[4];
and change your fread call to->
fread(ibsp, 4, 1, fp);
That should allow your program to run without doing nasty things to your computers memory.
You should probably study up a bit on pointers before you get too far into this project. You were trying to read the file into memory that you had not yet allocated. What's worse, you were trying to read the file into the memory allocated to store the address of the memory which you had not yet allocated
Edited by - novalis on November 7, 2000 3:47:36 PM
char ibsp[4];
and change your fread call to->
fread(ibsp, 4, 1, fp);
That should allow your program to run without doing nasty things to your computers memory.
You should probably study up a bit on pointers before you get too far into this project. You were trying to read the file into memory that you had not yet allocated. What's worse, you were trying to read the file into the memory allocated to store the address of the memory which you had not yet allocated
Edited by - novalis on November 7, 2000 3:47:36 PM
If a man is talking in the forest, and there is no woman there to hear him, is he still wrong?
Alright, that stopped the program from crashing, so now that function just fails. why?
Well, duh, ibsp doesn''t end with a null, right?
Use memcmp instead, or add the extra ''\0'' at the end of string.
"Paranoia is the belief in a hidden order behind the visible." - Anonymous
Use memcmp instead, or add the extra ''\0'' at the end of string.
"Paranoia is the belief in a hidden order behind the visible." - Anonymous
Ok, now I need to read an unsigned 32 bit integer...first of all, what is this? a float? a long? double? and how can I read this from the file?
Hmm I thought it was a DWORD...well how do i read it from a binary file stream? is there a specific fscanf code?
Well, you're both kind of wrong and kind of right.
There is no such thing as a DWORD unless you define it. For instance, the windows include file defines a DWORD type.
An unsigned int is not guaranteed to be a specific size. In fact, it is supposed to be the "most convenient" size for the processer that the compiler is building for.
The way to guarantee 32 bits of unsigned storage space in one variable is to declare it to be of type unsigned long. The C language guarantees a long to be 32 bits.
Now, to read it from a binary file, try this...
unsigned long i;
FILE *f;
.
.
.
fread(&i, 4, 1, f);
PS: Good call Staffan... I totaly missed that
Edited by - novalis on November 9, 2000 9:33:02 AM
There is no such thing as a DWORD unless you define it. For instance, the windows include file defines a DWORD type.
An unsigned int is not guaranteed to be a specific size. In fact, it is supposed to be the "most convenient" size for the processer that the compiler is building for.
The way to guarantee 32 bits of unsigned storage space in one variable is to declare it to be of type unsigned long. The C language guarantees a long to be 32 bits.
Now, to read it from a binary file, try this...
unsigned long i;
FILE *f;
.
.
.
fread(&i, 4, 1, f);
PS: Good call Staffan... I totaly missed that
Edited by - novalis on November 9, 2000 9:33:02 AM
If a man is talking in the forest, and there is no woman there to hear him, is he still wrong?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement