1 #include <msvcrt/conio.h>
2 #include <msvcrt/stdlib.h>
5 char *_cgets(char *string)
8 unsigned int maxlen_wanted;
12 * Be smart and check for NULL pointer.
13 * Don't know wether TURBOC does this.
17 maxlen_wanted = (unsigned int)((unsigned char)string[0]);
20 * Should the string be shorter maxlen_wanted including or excluding
21 * the trailing '\0' ? We don't take any risk.
23 while(len < maxlen_wanted-1)
27 * shold we check for backspace here?
28 * TURBOC does (just checked) but doesn't in cscanf (thats harder
29 * or even impossible). We do the same.
35 _cputs("\b \b"); /* go back, clear char on screen with space
38 sp[len] = '\0'; /* clear the character in the string */
48 /* special character ends input */
50 _ungetch(c); /* keep the char for later processing */
59 sp[maxlen_wanted-1] = '\0';
60 string[1] = (char)((unsigned char)len);