Difference between revisions of "Fwrite"
m (grandma) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
| style="width:10%" | '''''Switch''''' || Style="width:90%" | '''''Meaning''''' | | style="width:10%" | '''''Switch''''' || Style="width:90%" | '''''Meaning''''' | ||
|- | |- | ||
− | | b || indicates that a &binvar is being specified | + | | b || indicates that a [[:Category:Binary Files|&binvar]] is being specified |
|- | |- | ||
− | | n || appends a $crlf to the line being written. | + | | n || appends a [[$crlf]] to the line being written. |
|} | |} | ||
− | ''' | + | == 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. | ||
− | |||
== Example == | == Example == | ||
Line 24: | Line 44: | ||
/fwrite -n moo moo! | /fwrite -n moo moo! | ||
− | This will add ''moo!'' and a | + | This will add ''moo!'' and a $crlf to the end of the file assigned to the name ''moo''. |
/fwrite -b moo &moo | /fwrite -b moo &moo | ||
− | This will add the content of the | + | This will add the content of the Binary Variable &moo to the end of the file assigned to the name ''moo''. |
[[Category:File Handling]][[Category:Commands]] | [[Category:File Handling]][[Category:Commands]] |
Latest revision as of 08: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.