Author Topic: Write strings to file  (Read 5128 times)

nols

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
Write strings to file
« on: November 20, 2008, 02:17:11 pm »
Hi everybody,

am I to stupid or is this really so confusing?
I simply want to write a slick edit macro which writes strings to a file!
In C this code will do that:
Code: [Select]
int fh = f-open("temp.txt", "w");
f-write(fh, "This is a test");
f-write(fh, "Test done");
fclose(fh);

I didn't get it in Slick-C. I found the command _FileOpen(<filename>, <mode>) but i didn't know how to write to
this opened file. I search a command like f-write().

I tried _FileWrite() but slickedit couldn't find that command, maybe this doesn't exist.
I also tried to use _BlobWriteToFile() but this will write me binary data to the file, but i need ascii data!

Hopefully somebody can help me.
I've searched the SLICK_C_Macro_Programming.pdf but i couldn't find something about file handling :-(

Tobi

EDIT: Why get I an error message, when i try to send my post to the forum, when the post contains
f-open() without the dash??? So in the above code you have to leave out the dashes!!!
Hope you understand what I mean ;)

Graeme

  • Senior Community Member
  • Posts: 2274
  • Hero Points: 294
Re: Write strings to file
« Reply #1 on: November 21, 2008, 09:41:58 am »
You can use _open_temp_view to open a file  - see help contents -> macro functions by category -> file functions.

_open_temp_view creates a hidden buffer that you can write into using insert_line(), top(), bottom() etc  -  see macro functions by category -> editor control methods.

To save the current buffer, you can use save() or save_as().

Graeme

Graeme

  • Senior Community Member
  • Posts: 2274
  • Hero Points: 294
Re: Write strings to file
« Reply #2 on: November 21, 2008, 09:43:19 am »
Let's see if I can use fopen() ...

Edit : no problem with fopen using firefox 3.0.3
« Last Edit: November 21, 2008, 09:45:11 am by Graeme »

MindprisM

  • Senior Community Member
  • Posts: 126
  • Hero Points: 8
Re: Write strings to file
« Reply #3 on: January 09, 2009, 02:18:26 pm »
Attached is a module that does file IO using arrays.

Maybe that will be of use.