C Issue WAIT FOR DIGIT

Hi,
Was playing around with AGI in C and couldn’t seem to get this to work, was wondering if anyone had any ideas?
It answers but no matter what digit I hit it will wait the full 10 seconds before timing out and returning:
200 result=0

> #include <stdio.h>
> #include <string.h>
> #include <strings.h>

>     int main()
>     {
>       char buf[10240], line[1024];
>       FILE *f;

>       setlinebuf(stdout);
>       setlinebuf(stderr);

>       f = fopen("test.log", "a");

>       if (!f) {
>         return 0;
>       }

>       while (fgets(buf, sizeof(buf), stdin)) {
>         buf[strlen(buf)-1] = '\0';
>         if (*buf == 0) break;
>       }

>       fprintf(f, "answered\n");

>       fprintf(stdout, "WAIT FOR DIGIT 10000\n");
>       fflush(stdout);

>       fgets(line,80,stdin);

>       fprintf(f, "%s", line);
>       fclose(f);

>       return 1;
>     }

This ended up working. It was a port blocking problem.