Difference between revisions of "Fwrite"

From Scriptwiki
Jump to: navigation, search
(changed some links due to stupidity)
m (grandma)
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:
  
  
'''Note''' that it will append the text to the file. To overwrite / insert, you have to look at [[Fseek|/fseek]] before.
+
== Notes ==
 +
* The file handler must be [[Fopen|opened]] before using /fwrite.
 +
* When the file handler is first opened the pointer is at the end of the file so any /fwrite's upon opening the file handler will be appended to the file.
 +
* When writing to the file handler you're never inserting data, you're overwriting data unless the data you're writing at the pointer exceeds the end of the file.
 +
If you have a file containing this data below opened in a file handler called ''test'':
 +
A duck goes quack
 +
Dogs go woof
 +
Fish go moo
 +
Dana is silent but deadly
 +
And you issue the command:
 +
/[[fseek]] test -l 1
 +
/fwrite -n test Ducks go quack
 +
You will end up with a file containing:
 +
Ducks go quack
 +
k
 +
Dogs go woof
 +
Fish go moo
 +
Dana is silent but deadly
 +
The reason for this is /fwrite overwrites the same amount of data (unless exceeding the end of the file) from the file handler that you're writing (plus two if you issue -n for the [[$crlf]])
 +
A duck goes qu ac    k[[$crlf|<crlf>]]
 +
Ducks go quack [[$crlf|<crlf>]]
 +
The data, ''A duck goes qu'' is overwritten with ''Ducks go quack'' the original ''ac'' is overwritten with the [[$crlf|<crlf>]] from the -n switch leaving the k[[$crlf|<crlf>]] that was already there previously.
  
'''Note''' that the file has to be opened ([[Fopen|/fopen]]) before.
 
  
 
== Example ==
 
== Example ==

Latest revision as of 09:51, 26 January 2009

Writes text or the specified binary variable to the file.

/fwrite [-bn] <name> <text | &binvar>


Explanation of the switches:

Switch Meaning
b indicates that a &binvar is being specified
n appends a $crlf to the line being written.


Notes

  • The file handler must be opened before using /fwrite.
  • When the file handler is first opened the pointer is at the end of the file so any /fwrite's upon opening the file handler will be appended to the file.
  • When writing to the file handler you're never inserting data, you're overwriting data unless the data you're writing at the pointer exceeds the end of the file.

If you have a file containing this data below opened in a file handler called test:

A duck goes quack
Dogs go woof
Fish go moo
Dana is silent but deadly

And you issue the command:

/fseek test -l 1
/fwrite -n test Ducks go quack

You will end up with a file containing:

Ducks go quack
k
Dogs go woof
Fish go moo
Dana is silent but deadly

The reason for this is /fwrite overwrites the same amount of data (unless exceeding the end of the file) from the file handler that you're writing (plus two if you issue -n for the $crlf)

A duck goes qu ac     k<crlf>
Ducks go quack <crlf>

The data, A duck goes qu is overwritten with Ducks go quack the original ac is overwritten with the <crlf> from the -n switch leaving the k<crlf> that was already there previously.


Example

/fwrite moo moo!

This will just add moo! to the end of the file assigned to the name moo.


/fwrite -n moo moo!

This will add moo! and a $crlf to the end of the file assigned to the name moo.


/fwrite -b moo &moo

This will add the content of the Binary Variable &moo to the end of the file assigned to the name moo.