Jump to content

» «

add new line to text file

  • This topic is locked This topic is locked
3 replies to this topic
  • gokuta

    Square Civilian

  • Members
  • Joined: 24 Apr 2014
  • Afghanistan


Posted 04 May 2014 - 10:54 PM Edited by gokuta, 04 May 2014 - 10:55 PM.

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?

  • Ashwin.Star

    i'll be back...

  • Members
  • Joined: 14 Nov 2010
  • India


Posted 05 May 2014 - 02:13 AM Edited by Ashwin the new boy, 05 May 2014 - 02:14 AM.

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

  • Deji

    Coding like a Rockstar!

  • FerocYEE
  • Joined: 24 Dec 2007
  • None
  • Contribution Award [Mods]


Posted 05 May 2014 - 12:23 PM Edited by Silent, 05 May 2014 - 07:12 PM.

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 [email protected] 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 [email protected] 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.):


  • gokuta

    Square Civilian

  • Members
  • Joined: 24 Apr 2014
  • Afghanistan


Posted 05 May 2014 - 02:29 PM

Thanks, Deji (and Ashwin), that was helpful. Sorted!

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users