pff@beach.cis.ufl.edu (Pablo Fernicola) (09/12/89)
Okay, I thought this was going to be simple but it wasn't (after all it deals with computers :-) ). I'm trying to pop up a little window where the user gets to type some input and whatever is typed is echoed back. Here is a fragemnt of my code main() { char input[15]; int charCount; [init graphic stuff] [init font stuff] qdev( KEYB ); [cmove instruction] fmprstr( "Enter string : "); [cmove instruction] charCount = 0; while( charCount <= 14 ) { qread( input[ charCount ] ); fmprstr( input ); charCount++; } } I get the window, I get the message Enter string and then I crash. Any clues are wellcomed. -- pff@beach.cis.ufl.edu Pablo Fernicola - Machine Intelligence Laboratory - UF "If we knew how it works, it wouldn't be called research."
thant@horus.sgi.com (Thant Tessman) (09/12/89)
In article <20862@uflorida.cis.ufl.EDU>, pff@beach.cis.ufl.edu (Pablo Fernicola) writes: > Okay, I thought this was going to be simple but it wasn't (after all > it deals with computers :-) ). > > I'm trying to pop up a little window where the user gets to type some > input and whatever is typed is echoed back. > > > Here is a fragemnt of my code > > main() > { > char input[15]; > int charCount; > > > [init graphic stuff] > [init font stuff] > > qdev( KEYB ); > > [cmove instruction] > fmprstr( "Enter string : "); > [cmove instruction] > charCount = 0; > while( charCount <= 14 ) > { > qread( input[ charCount ] ); ^^^^^^^^^^^^^^^^^^ Change to either: qread( &input[charCount] ); or: qread( input + charC ); > fmprstr( input ); > charCount++; > } > } > thant -- ----------------------------------------------------------------------------- There's a pattern there to see, and the point will soon be clear to me. -Stewart Copeland -----------------------------------------------------------------------------
donl@glass.wpd.sgi.com (donl mathis) (09/13/89)
In article <41627@sgi.sgi.com>, thant@horus.sgi.com (Thant Tessman) writes: > > char input[15]; > >[...] > > qread( input[ charCount ] ); > Change to either: > qread( &input[charCount] ); > or: > qread( input + charC ); Closer, but it doesn't seem quite right. Qread's argument is supposed to be the address of a short, not a character. I'm too tired to figure out which half of the short the character is in and which neighboring character gets trashed, but it seems like a bad idea in any case. It might also be wise to check that (qread() == KEYBD) before you assume that you're getting a character. Here's my best guess, without echoing... #include <gl.h> #include <device.h> main () { char buff [128], *p; short dev, ch; winopen ("temp"); qdevice (KEYBD); p = buff; while (dev = qread (&ch)) { if (dev == KEYBD) { if (ch == '\n' || ch == '\r') { break; } *p++ = ch; } } *p = '\0'; printf ("%s\n", buff); gexit (); exit (0); } -- - donl mathis at Silicon Graphics Computer Systems, Mountain View, CA donl@sgi.com
msc@ramoth.sgi.com (Mark Callow) (09/15/89)
My guess is that you are overflowing your input buffer because qread is returning more than just keystrokes. For example, there will be an INPUTCHANGE event. Also qread returns shorts not chars so you definitely overrun it on the 15th character you type. -- From the TARDIS of Mark Callow msc@ramoth.sgi.com, ...{ames,decwrl,sun}!sgi!msc "There is much virtue in a window. It is to a human being as a frame is to a painting, as a proscenium to a play. It strongly defines its content."