Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Help with reading files

Author
Message
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 1st Dec 2007 05:56
Hello Everyone,

I am having trouble with the following function:


What I am trying to do is get open this file from my hard drive, read the contents, then print them onto the screen. I put the 'if statement' there to test if it was even finding the file, and it is. Can anyone give any pointers? Thanks in advance.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 1st Dec 2007 10:49
I don't see anything wrong with that, it seems it should read a text file of 60 characters long each time called. What is the problem?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2007 12:30
I'd advise you to simply dump the GDK file I/O functions and switch to either the C or C++ library instead. What you have there is an open invitation to a buffer overflow - if your message is over 60 bytes in size, it will read it all in anyway and overwrite the memory after the buffer.



There you go - no chance of a buffer overflow

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 1st Dec 2007 17:15
The problem is it wasn't displaying any text at all from the file i was trying to open.

IanM, I tried it the way you recommended, but now i am getting a link error:



I put the headers up there, is there anything else special i need to do? Thanks for both your input so far.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2007 19:15
See if this works for you: Right-click on your project and select properties, then set C++->Code Generation->Runtime library to Multi-threaded

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 1st Dec 2007 20:14
Hey it worked like a charm Thank you so much.

Login to post a reply

Server time is: 2024-10-08 18:19:26
Your offset time is: 2024-10-08 18:19:26