File Manipulation Help
-
There doesn't seem to be very much documentation on file manipulation and I had a couple questions:
- How do you clear a file?
I tried to write a char(0) , \0, \z but none of them clear out the data of the file or at the location they are being written.
- Can you seek by line?
It would be nice to seek by line but I don't think this is an option. Do I just need to write a function that iterates through every char, counting the number of new line chars until it reaches the desired line?
- Is there any way to tell where the end of the file is?
Does Fuze implement an EOF char or a way to access the number of chars in a file? When reading a file I have no idea when to stop.
Thank you for any help 😊
-
Not currently. I write a count at the start to record the number of records in the file. Take a look at this post: https://fuzearena.com/forum/topic/781/persistent-data
-
To clear a file. You'll need to substitute a character for a NULL. Therefore if you use "#" as the substitute you'll need to ignore that character when reading from the file. If you want to read line by line, you'll need to put the read() function within a loop and read one char at a time until you reach a char(10) which will end the loop and concatenate the read chars to a string. Then repeat. When storing the length of the file. You could utilize the first 5 chars of a file or how many you need to store data about the current file. Such as file size, where the cursor should be, etc.
-
@LucasJG25 that seems like a lot to manage for simple file manipulation. Isn't EOF and Null chars the foundation of any file read/write implementation?
This would get really sloppy especially when I am still in the process of developing and don't know the exact structure of my file. Now I just have this big file with a bunch of "#" in it? -
@HeavyByte That is true, though for now we have to make do with what we can come up with so far. But I'm sure the Fuze team have these issues in mind and will make improvements in later patches.