Jump to content

add new line to text file


Recommended Posts

I need to add new line to a text file. File is opened as text file (not binary) because I need to put some symbols there too. What opcode (or several opcodes) should I use?

Edited by gokuta
Link to comment
Share on other sites


Write "0D 0A" these two bytes to the File,in order to start from a new Line,

Edited by Ashwin the new boy
Link to comment
Share on other sites

If you're doing this with CLEO 4, you can use a trick to get over the lack of escape sequences in SB:


0ACE: print_help_formatted "Line #1%cLine #2" 0xA
The %c specifier in format strings will read the value of any number and display it as the relevant ASCII character. 0xA is the '\n' newline character.


This should print 2 lines of help text. Similarly, if you want to output a new line to a file:


0AD9: write_formatted_string_to_file 0@ format "My File...%c" 0xA
However, this will only work if you've opened the file in text mode, as the 0xA will actually be translated to 0x0D0A, as that is the proper way to end lines in files on Windows. If you were to open it in plain binary mode, you'd have to write that yourself:


0AD9: write_formatted_string_to_file 0@ format "My File...%c" 0x0D0A


As all CLEO commands commonly just bridge functions from C libraries, here is the reference for fopen - with links to similar file IO functions you may find in CLEO (fread/fwrite/etc.):



Edited by Silent
Link to comment
Share on other sites

This topic is now closed to further replies.
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.