| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | [1/2] My fgets() |
>>> Part 1 of 2...
FWIW, this is my string input routine, similar to Editgets, but with less
rubbish in it. Compiled on TC v2 without errors,warnings, ANSI on.
Feel free to use it,not use it, or flame me for posting such a rubbish.
Ideas on improvements would be welcome.
#include
#include
#include
#include
#include
#define TEST
#define ESC 27
#define ENTER 13
#define LARROW 331
#define RARROW 333
#define END 335
#define HOME 327
#define BSP 8
#define TAB 9
#define SPACE ' '
#define TABSPACE 8
#define INSERT 338
#define DELETE 339
#define FLUSHKEY while(kbhit()){getch();}
char *getstrdefd(char*,int);
int getkey();
#ifdef TEST
main()
{
char *str1,*str2;
clrscr();gotoxy(10,10);
str1 = "Hello World";
str2 = getstrdefd(str1,40);
if(str2)
{
printf("\n\nOriginal string: %s -> Length : %d",str1,strlen(str1));
printf("\n New string : %s -> Length : %d",str2,strlen(str2));
}
else printf("\nNULL returned ! ");
return 0;
}
#endif
char *getstrdefd(char* def,int len)
{
char *retstr;int key = 0,strpos = 0,maxpos = 1,tempos,savepos,insmode = 0;
int x,y;
x = savepos = wherex();y=wherey();
if((retstr = (char*) calloc((len+1),sizeof(char))) == NULL) return NULL;
if(def){
printf("%s",def);
strncpy(retstr,def,(maxpos = strlen(def)));
gotoxy(x,y);
}
for(;;) /* editing starts here */
{
key = getkey();
if(!isprint(key))
{
switch(key)
{
case ESC : return def;
case ENTER : {
retstr[maxpos] = 0;
_setcursortype(_NORMALCURSOR);
return retstr;
}
case INSERT : (insmode ^= 1) == 1 ? _setcursortype(_SOLIDCURSOR) :
_setcursortype(_NORMALCURSOR);
break;
case HOME : strpos = 0;x = savepos;gotoxy(savepos,y);
break;
case END : strpos = maxpos;x = maxpos + savepos;gotoxy(x,y);
break;
>>> Continued to next message...
___ Blue Wave/DOS v2.21
--- Maximus 3.00
* Origin: The Software Parlour (3:635/544)SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 711/401 409 410 413 430 SEEN-BY: 711/510 808 809 932 934 712/515 713/888 714/906 800/1 7877/2809 @PATH: 635/544 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.