tutorial:file_operations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:file_operations [2020/11/20 02:02]
iridescence [Rust]
tutorial:file_operations [2021/12/23 09:45] (current)
daveon_newearthlife [File Operations]
Line 2: Line 2:
  
 In most software applications that require large sets of data or interaction which cannot be expressed before compile time, we use files to store large sets of data and other information that we may require for our programs. These files and folders can be accessed by our program in order to carry out the program's intended purpose. This could be configuration files in formats like JSON, INI, PROPERTIES, TOML, etc. or maybe textures for your games and applications or audio for music playback and so many more uses! In most software applications that require large sets of data or interaction which cannot be expressed before compile time, we use files to store large sets of data and other information that we may require for our programs. These files and folders can be accessed by our program in order to carry out the program's intended purpose. This could be configuration files in formats like JSON, INI, PROPERTIES, TOML, etc. or maybe textures for your games and applications or audio for music playback and so many more uses!
 +
 +
 +
  
 ===== General Theory ===== ===== General Theory =====
Line 53: Line 56:
 } }
 </code> </code>
 +
 +In the C example we use the C FILE* in order to open the files via fopen and uses fprintf and fread in order to work with the file handle. In C++ we have to use an ifstream and ofstream to read and write respectively. The C example also will work in C++ - and you technically only need one FILE* in C. A pure fstream does not work in this instance on the PSP. In C++ we also use the getline method to read until a newline.
  
 ===== Rust ===== ===== Rust =====
Line 87: Line 92:
 } }
 </code> </code>
 +
 +In Rust, we use the IoFileMgr module in order to work on our application. This application requires that the hardcoded path is valid. We then write to a file opened in create mode and then close it. We then reopen it in read mode and then read to our array. Finally, we derive a string from the raw utf8 and print it out to the screen.
  
 ===== Zig ===== ===== Zig =====
Line 122: Line 129:
  
 </code> </code>
 +
 +In Zig, we set up the Custom OS for STD via pub const os = @import("pspos.zig");. This sets up our custom OS so that Zig can support our application. Then it's just a matter of creating a file in truncate mode in order to overwrite it. Then we simply use print to print out, and read into the buffer to read our text back in. Finally, we use the printFormat method in order to create a printed string.
  • tutorial/file_operations.1605837773.txt.gz
  • Last modified: 2020/11/20 02:02
  • by iridescence