gets() works with global buffer but not with a local buffer
Posted: Sun Mar 19, 2006 1:21 pm
This code has a very strange problem
this works perfect with a global buffer but when it is allocated on the stack(local) it prints letters perfect but the buffer has different characters(same length)
so what the crap is wrong with this:
the weird part is that the ascii key is copied to the buffer and then putchar(buffer) is done so it at one point is in the buffer right
this works perfect with a global buffer but when it is allocated on the stack(local) it prints letters perfect but the buffer has different characters(same length)
so what the crap is wrong with this:
the weird part is that the ascii key is copied to the buffer and then putchar(buffer) is done so it at one point is in the buffer right
Code: Select all
extern char getkey(char *buf);
char *gets(char *buf){ //get a string from the keyboard
int x,y;
char tmp[1];
x=cwin->curx;
for(;;){
getkey(tmp);
//tmp[1] is asci code; tmp[0] is scancode
if(tmp[1]==0){
switch(tmp[0]){
}
}else{
switch(tmp[1]){
//case 27:
//buf--;
//break;
case '\n':
//enter/return
*buf=0;
return buf;
break;
case '\b':
if (x<cwin->curx){
buf--;
*buf=0;
cwin->curx--;
putchar(' ');
cwin->curx--;
}
break;
default:
//*buf=tmp[1];
*buf=tmp[1];
putchar(*buf);
buf++;
break;
}
}
}
//buf--;
//*buf=0;
}