short foundword= 0, eraseamount= -1; /* doesn't work in situation in which there are whitespaces after word Example: bar foo___(ctrl-backspace here) Result should be bar_ but is bar foo___ _ is whitespace */ for(x=but->pos; x>=0; x--) { if(str[x] != ' ' && foundword == 0) /* there are other possibilities also? */ foundword= 1; if(str[x] == ' ' && foundword == 1) break; eraseamount++; }