Of course, the bit with fseek(stdin, 0, SEEK_END) will cause it to skip
all but the first ten bytes if stdin is redirected to a file. :-)
On Tue, 23 Mar 1999, Bogdan Taru wrote:
> Hi friends,
>
> Sorry to bother you again. Back to my old C problem... Given this
> sequence of code:
>
> /*-----------------------------do_nothing.c-----------------*/
> char *s;
>
> while(1){
> s = malloc(10);
> fgets(s, 10, stdin); /*stdin means console, right???*/
> free(s);
> }
> /*----------------------------------------------------------*/
>
> I've got this problem:
> The first time the loop is executed, everything works ok, 's' is filled
> with 9 characters plus '\0', but in the next loop, it doesn't read
> anything from the console, but reads from the buffer(if the text
> introduced the first time is > 10char). How can I make it read from the
> console at each loop? I've tryied anything I know: fflush(stdin),
s='\0'
> at the beginning of each loop, even the malloc & free inside the loop,
> like above...
>
> Hope I'm not too boring... Thanks...
>
> Have fun,
> bogdan
>
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]