Re: help with window widgets



On Sat, 2006-11-11 at 20:05 -0800, ybisou wrote:
Hi,[...]
Hello! :-)

I'm writing a code that should allow me to read a list of int(one at the
time) from a STDIN into my GTK program.

Eventually you'll probably want to do this by registering stdin as
a file descripter (fileno(STDIN), or just 0) so that gtk calls a
function whenever data is available.  This way your program can
be updating the display while more numbers arrive.

Some toolkits have "on-each-line-of-input-from-fd" but I don't think
that's included in gtk unfortunately.

 The reading is fine but I am trying
to output those numbers into a window. I can ouput the first number but I
can't refresh and ouput the second number or the rest of the numbers.

While your program is in "read" it is blocked, and gtk windows can't
refresh.

I'm doing something like this, and the windows only shows the first number.
Please help...

//widgets initializations

while( read(0,&x,strln(x))

this is certainly not what you want.  I think you need something like,
unsigned char buffer[BUFSIZ];
while (read(0, buffer, BUFSIZ - 1)) ...

strlen is measuring the number of characters before the first 0 byte
in the string.

More likely you want fgets() here in fact.  But when you move
to callbacks you'll need to use read() so you might as well
deal with it.  Note also that read() might not give you a complete
line of input, or might give you multiple lines, depending on
e.g. whether the input comes from a terminal or a program, and on
how it's generated.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]