Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

justinwalsh

converting fread code to ifstream code, need help

This topic is 5226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am converting NeHe''s lesson 33 code useing stdio to useing the fstream instead. All my code loads properly, and works but i have a qustion about this line below... C fread version... if(fread(texture->imageData, 1, tga.imageSize, fTGA) != tga.imageSize) { now i made this code below, where TGAin is a pointer to an ifstream object. Is this the correct version of the code above? C++ ifstream version... TGAin->read((char*)texture->imageData, tga.imageSize); if(sizeof(texture->imageData) != sizeof(tga.imageSize)) { I dont understand stdio.h, and have never used it, so i think this is correct, please let me know.

Share this post


Link to post
Share on other sites
Advertisement
sizeof() returns the size of the type that you specify in bytes. It works at compile-time and therefore cannot resolve the length of a dynamic array; it merely returns the size of a pointer (4 bytes).

If you want, I can give you my ifstreamed version of the tga loading code. I only converted the uncompressed version, but I''m thinking about finishing the job sometime soon.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
Check the return value of TGAin.read for the number of bytes read - sizeof(texture->imageData) and sizeof(tga.imageSize) are compile-time constants dependent only on the static type of your variables.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites
ok, so is this code correct then?


TGAin->read((char*)texture->imageData, tga.imageSize);
if(TGAin->gcount() != tga.imageSize) {

[edited by - justinwalsh on February 28, 2004 1:10:01 PM]

Share this post


Link to post
Share on other sites
Yes, that looks ok to me.


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!