Re: write binary file with struct in tcl




Read the man page for binary format. Its very similar to the binary scan
options, after you have the entry in a variable you can use puts to
write it to a file (which should be configured as binary as for reading).

Michael

This what I did by use binary format

set fp [open ./add.dat w]
set outBin [binary format Ia5xxxa80xxx 1 cmd passwd]
fconfigure $fp -translation binary
puts -nonewline $fp $outBin
close $fp

what I get in add.dat is :

^@^@^@^Acmd^@^@^@^@^@command^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

but for chkr2k3.dat which create by C it show:

^A^@^@^@cmd^@:command^@^D~B^D^H^D~B^D^H
~G^D^H^T~^^D^H@~]^D^Hl๘ฟฟ๖ท^DH^D^@^@^@^@r^EH๔๗ฟฟ�~G^D^H^T~^^D^H@~]^D^Hl๘ฟฟ^@r^EH^ZN^MH^P~L^D^H^X๘ฟฟต~D^D^H^A^@^@^@

The purpose of my program is I would like to get the value from
interface to write in binary file by Tcl programming and then read
that binary file use C programming so I try to see how write binay file
in the same format in C struct which I use

However, Thank you so much for all of your suggestion

.



Relevant Pages

  • Re: write binary file with struct in tcl
    ... after you have the entry in a variable you can use puts to ... set outBin [binary format Ia5xxxa80xxx 1 cmd passwd] ... set passwdstuff "lksjdflksdjf lkasjf laksjf laksdjf alskfj slkfjsd lflasdkjfsldkfjsd" ... that binary file use C programming so I try to see how write binay file ...
    (comp.lang.tcl)
  • Im New
    ... programming found ruby and started following a guide. ... then puts 'What? ... Sonny speak louder! ...
    (comp.lang.ruby)
  • Re: open email to the W3C
    ... >some sort of "character" format as opposed to binary format? ... Oliver, I have been programming computers for a living for 42 years. ...
    (comp.lang.java.advocacy)
  • Re: How to search a Word Document for keywords using TCOM and TCL
    ... set text {"Tcl-Tk is a great programming language" \ ... "Tcl-Tk est un super language de programmation" \ ... puts "$start" ...
    (comp.lang.tcl)
  • Re: [QUIZ] FizzBuzz (#126)
    ... I couldn't resist throwing in the Loki solution. ... def self.invoke it ... puts i.options ... This is, obviously, an incredibly easy programming puzzle -- as far as ...
    (comp.lang.ruby)