BS> MT> Is there any simple way to use it with strings of 80
BS> MT> or more characters, with it not shuffling the cursor
BS> MT> down in that fashion?
BS> Not in the current version. If you rework it to do so,
BS> I'd invite you to submit it to SNIPPETS. Right now, I
BS> don't have timeto do even moderate size fixes.
How about doing something like this?
/*_|_| BIGSTR.C PUBLIC DOMAIN Kurt Kuzba (12/24/95)
_|_|_| This program demonstrates the use of ANSI functions to
_|_|_| construct and implement a function to return a string from
_|_|_| the keyboard. (The non-standard function, getch(), is used.)
_|_|_| HOME, END, LEFT, RIGHT, BACKSPACE, INSERT, DELETE, and all
_|_|_| the text keys are allowed for use. A prompt is optional.
_|_|_| A pointer to the default string is returned. There must be a
_|_|_| default string with sufficient space for the return string.
_|_|*/
#include
#include
#include
#include
char *getstr(char*,char*,int,int);
int main(void)
{ char name[33] = "Unknown", buf[33] = "";
int age = 0;
getstr("\nEnter your name: => ", name, 30, 16);
while(age < 1 )
if( (age = atoi(getstr("\nEnter your age : => ", buf , 2, 2))) < 1)
puts("\nNot a valid age. Re-enter data:");
printf("\n\nNAME: %s\n AGE: %d\n", name, age);
return 0;
}
char *getstr(char *prompt, char *dfault, int strlimit, int winlimit)
{ char temp[256] = "";
int len = sprintf(temp, "%s", dfault), key = 0, offset = 0,
marker = 0, count, home, INS = 1;
printf(prompt);
while(key != '\r')
{ for(count = 0, key = 1; count < winlimit; count++)
{ if(key)
if(0 != (key = temp[offset + count])) putchar(key);
else putchar('-' + 50 * INS);
else putchar('-' + 50 * INS);
}
printf("%c\b", '-' + 50 * INS);
for(count = marker - offset; count < winlimit; count++)
putchar('\b');
home = marker - offset;
switch(key = ((key = getch()) == 0) ? -getch() : key)
{ case -82: INS = !INS; putchar('\a'); break; /* INSERT */
case -75: if(marker) /* LEFT */
if(--marker < offset) offset = marker; break;
case -77: if(marker < len) /* RIGHT */
if(++marker - offset > winlimit) offset++;
break;
case -71: marker = offset = 0; break; /* HOME */
case -79: offset = (len > winlimit) ? len - winlimit : 0;
marker = len; break; /* END */
case '\b': if(!marker) printf("\a"); /* BACKSPACE */
else { char *bs = &temp[marker--];
len--;
while((*(bs - 1) = *bs) != '\0') bs++;
if(marker < offset) offset = marker;
} break;
case -83: if(marker == len) printf("\a"); /* DELETE */
else { char *bs = &temp[marker];
while(0 != (*bs = *(bs + 1))) bs++;
len--;
} break;
case '\r': strcpy(dfault, temp); break; /* RETURN */
case 25: /* CTRL/Y */
temp[len = offset = marker = 0] = '\0'; break;
case 27: key = '\r'; break; /* ESCAPE */
default : if(key 127) break; /* TEXT */
if(marker >= strlimit) putchar('\a');
else { if(INS && len < strlimit)
for(count = len++; count > marker; count--)
temp[count] = temp[count - 1];
temp[marker++] = (char)key;
len += (len = len);
temp[len] = '\0';
if((marker - offset) >= winlimit)
offset = marker - winlimit;
} break;
}
for(count = home; count > 0; count--) putchar('\b');
}
return dfault;
}
/*_|_| end BIGSTR.C */
> ] Never ask for justice. Trust me... You won't like it........
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)
|