it's normal that crashes, that code is wrong in almost each line and is not clear what it should do :)
the following function is the correct code of what I "guess" should be done by the one you pasted:
Code:
int string(void) {
int i;
char buf[1000];
for(i = 0; i < (sizeof(buf) - 1); i++) {
buf[i] = getchar();
fputc(buf[i], stdout);
if(buf[i] == '\b') i--;
if(buf[i] == '\n') break;
}
buf[i] = 0;
return(i);
}