Quantcast

Jump to content

» «
Photo

add new line to text file

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

    Crackhead

  • Members
  • Joined: 24 Apr 2014
  • Afghanistan

#1

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
  • Ashwin.Star

    i'll be back someday

  • Members
  • Joined: 14 Nov 2010
  • India

#2

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
  • Deji

    Coding like a Rockstar!

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

#3

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 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
EDIT:

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.):

http://www.cplusplus...e/cstdio/fopen/

gokuta
  • gokuta

    Crackhead

  • Members
  • Joined: 24 Apr 2014
  • Afghanistan

#4

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