[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

C fwrite equivalent in ruby

Lyes Amazouz

9/30/2008 3:10:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hello list

I want to know if there is an equivalent to the C function fwrite in ruby.
Remeber that fwrite takes a buffer and a size of Bytes to write.

the method "write" of the File object takes only the buffer to write as a
parameter, but what I want to do is to write only an amount of bytes from
this buffer, not all the buffer.

Thank you!
--
===========
| Lyes Amazouz
| USTHB, Algiers
===========

3 Answers

ara.t.howard

9/30/2008 3:29:00 PM

0


On Sep 30, 2008, at 9:09 AM, Lyes Amazouz wrote:

> Hello list
>
> I want to know if there is an equivalent to the C function fwrite in
> ruby.
> Remeber that fwrite takes a buffer and a size of Bytes to write.
>
> the method "write" of the File object takes only the buffer to write
> as a
> parameter, but what I want to do is to write only an amount of bytes
> from
> this buffer, not all the buffer.
>
> Thank you!
> --
> ===========
> | Lyes Amazouz
> | USTHB, Algiers
> ===========



io.write buffer[0,len]


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Mark Thomas

9/30/2008 3:43:00 PM

0

On Sep 30, 11:29 am, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> io.write buffer[0,len]

or call io.putc(byte) as many times as necessary.

-- Mark.

Robert Klemme

9/30/2008 8:55:00 PM

0

On 30.09.2008 17:43, Mark Thomas wrote:
> On Sep 30, 11:29 am, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
>> io.write buffer[0,len]

One additional remark: String#[] does not copy the internal buffer, so
you do not have to worry about wasting too much memory.

> or call io.putc(byte) as many times as necessary.

This is likely inefficient.

Kind regards

robert