Re: getc/ReadFile after gets problem
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Dec 07, 2006
- 642 views
Pete Lomax wrote: > > I think there is some wierd buffer-effect going on inside gets/getc. > After gets(0), getc(0) will wait for new input, whereas a call to the > windows API function, c_func(xReadFile,{stdin,chr,1,count,0}) yields > both the \r and \n, that I thought would have been "eaten" by gets(0)?? > > Here is some code that behaves strangely, any clues?: <snip> > > With getc(0), type in "ABC\n", it outputs {65,66,67,10} and waits for input. > With mygetc(0), it outputs the 10 twice, but you only need to key it once! > > Does anyone (with some knowledge, perhaps, of C|be_runtime.c) have any Ideas? > There is something > Somewhere in there it (I think) shoves a read character back into the input > > stream, but I can't follow C code with all those #ifdefs... > I think the problem is in be_runtime.c/key_gets(). if (c == '\r' || c == '\n' #ifdef EWINDOWS || c == 284 #endif ) break; else if (c == BS || c == LEFT_ARROW #ifdef ELINUX //FOR NOW - must decide what to do about different key codes || c == 263 #endif ) { if (column > init_column) { column = column - 1; SetPosition(line, column); screen_output(NULL, " "); SetPosition(line, column); input_string[column - init_column] = '\0'; } } You'll notice that eu will delete the character if you use the left arrow, where as windows will just move the cursor. The solution is probably to output the newline, and to get rid of the screen_output(NULL, " ") in the left arrow case. Matt