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 / Inputs,write and read files.

Author
Message
Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 4th Feb 2009 14:00 Edited at: 4th Feb 2009 14:28
Allright I've read some posts about writing stuff to files,inputs but still am confused.

First what I am using for writing:

This one works pretty well.

But how to read results?
ADDED ON EDIT: And how to store them in the variable?


Next. I want to make simple input/output that resets on Return keypress.

What I've tried:

But I got: "You wrote: (null)" and text appears behind "(null)".

Any help will be appreciated.

-Murloc.

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 4th Feb 2009 19:38
Bringing Up My Post

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Feb 2009 23:18
Well, if you trust the input, you can use fscanf to read data back from your file:


The problem there is that malformed input (either accidental or deliberate) can cause a buffer overrun. Oh, and %s will read back a word (ie up to a white space), and not necessarily what you wrote to the file in the first place.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 6th Feb 2009 23:55
I haven't done anything with the C level files in a while, so I'll be a bit vague. I prefer to put pertinent data in structs in their binary form and save the struct to a file opened in binary mode then read them into a struct the same way. Bear in mind that in order to preserve text data you must have it stored in a char array instead of using pointers. IMS, the saving to the file requires the file pointer, the address of the struct being saved and the size of the struct. Reading in then becomes a matter of opening the file in binary mode and doing a read operation with the same kind of parameters.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-09-30 17:24:16
Your offset time is: 2024-09-30 17:24:16