Skip to main content
GameDev.net gamedev.net
🔒 Locked

Wierd File Access Error

Started by Galileo430 Oct 23, 2000 at 2:35 AM 3 replies 300+ views
Original Post
Galileo430
Galileo430
Ok I use fread to read a file.
    
// This works.

char data[1000];

fread(data, sizeof(data), 1, stream);

// This does not?!?

char *data;
int length;

length = 1000;
data = new (char[length]);
fread(data, sizeof(data), 1, stream);

    
Anyone know what I did wrong with the second one? ------------------------------------------------------------ I wrote the best video game ever, then I woke up... Grandus.Com
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Digger
Digger
Replace the line:

fread(data, sizeof(data), 1, stream);

with

fread(data, length, 1, stream);
Digger
Digger
Replace the line:

fread(data, sizeof(data), 1, stream);

with

fread(data, length, 1, stream);
karmalaa
karmalaa
I''ll suggest to use



fread(data, sizeof(char), length, stream);



since ''sizeof(data)'' is equal to ''sizeof(char *)'' in the second case!


Bye,

Karmalaa

---[home page] [[email=karmalaa@inwind.it]e-mail[/email]]
Galileo430
Galileo430
Worked! Thanks So Much Guys!
------------------------------------------------------------I wrote the best video game ever, then I woke up...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.