Date: Tue, 7 May 1996 16:14:50 -0400 (EDT) From: Justin Ward To: djgpp AT delorie DOT com Subject: totally crazed output Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII okay I've been getting some REALLY bizarre results from printf. I have a function which reads a string from the console using getch. It takes care of 'special' keys (^C, enter, ^H, etc), and then uses putch to echo the char to the screen, again handling special keys accordingly. It then returns the string, as well as putting it into the buffer it takes as one of its arguments. Now this is all fine well and good. Here comes the problem though.. printing the string. I call printf("input: %s\n", s); and things go haywire. It prints "input: " and then the string, and then the I and the N in input get screwed. If the string returned has a length of zero (ie, s[0] == NULL), the i becomes one of the characters used to make a "box" on an ascii text display, and the n becomes a heart character.. Okay. So then I test it entering ONE character in the string. This time the exact same thing happens, only the n stays normal. great. Next I enter a nice long string.. everything works FINE. Now I'm thoroughly puzzled. I run another test, this time just using ^G, which pauses output while it sounds the bell. Get this. It prints "input: " on the screen, sounds the bell, and THEN the i becomes the box char. Screwy enough for you? wait, there's more. I run the test AGAIN, hit F1 twice (which, btw, getch doesn't seem to get. any ideas on this?), then hit enter. Now the string is empty, but it prints input normally and it STAYS normal. The code below is rather lengthy, I know, but what can I say.. Anyway if anybody has ANY ideas on what the hell is going on here, I'm dying to figure it out. Justin justin AT yoss DOT canweb DOT net ward AT stealth DOT net ---begin nsh.cc--- /* nsh.c * main function and other crap. * * insert GNU crap here. */ #include "nsh.h" #include #include #include /* int GetX() { int x,y; ScreenGetCursor(&x, &y); return x; } int GetY() { int x,y; ScreenGetCursor(&x, &y); return y; } */ void sig_int(int whoknows) { // don't do anything. } main(int argc, char *argv[]) { char input[120]; clrscr(); /* readini(); */ signal(SIGINT, sig_int); getstring(input, 120); printf("\ninput: %s\n\n", input); } --end nsh.cc-- --begin getstr.cc-- #include "nsh.h" #include #include #include #include #include // backspaces on the console one. putch('\b') just moves cursor back, does // not remove char from screen. void backspace() { putch('\b'); putch(' '); putch('\b'); // move back again since space moved cursor forwards one. } // prints a control char the way it was meant to be printed. void putctrl(char c) { putch('^'); if (c==0) putch('@'); putch(c+64); } // end function putctrl. char *getstring(char *s, int len) { int index=0; Bool special=FALSE; for (;index