feasibility of stdin stream to feel up directly.

V

vin pane

For flushing up ( I mean to drop) all the present contents of stdin
stream Can I use the "memset(stdin, 0, 50); " function ?
I want to ask the feasibilty of this code . Will it cause any problems
? I know such operations are not supposed to be done on the streams ,
but steel this functions offers a void pointers to be passed.

thank you in advace.
 
J

Joona I Palaste

vin pane said:
For flushing up ( I mean to drop) all the present contents of stdin
stream Can I use the "memset(stdin, 0, 50); " function ?

You must certainly can not. memset() does not work on streams. The
above would cause undefined behaviour.
I want to ask the feasibilty of this code . Will it cause any problems
? I know such operations are not supposed to be done on the streams ,
but steel this functions offers a void pointers to be passed.

The code is pretty much completely infeasible, and will cause no end of
problems.

What do you mean by "drop all present contents of stdin"? If you really
want to clear all data that has currently been entered into stdin, but
not yet read, then that's an operating system issue, and impossible in
portable C.
However, if you simply want to discard all extraneous input before the
next newline, there are a few good techniques in the comp.lang.c FAQ.
 
J

Jonathan Burd

vin said:
For flushing up ( I mean to drop) all the present contents of stdin
stream Can I use the "memset(stdin, 0, 50); " function ?
I want to ask the feasibilty of this code . Will it cause any problems
? I know such operations are not supposed to be done on the streams ,
but steel this functions offers a void pointers to be passed.

thank you in advace.

void eat_stdin()
{
int ch;
while (ch = getchar() != EOF);
}

Regards,
Jonathan.
 
J

Jonathan Burd

Jonathan said:
void eat_stdin()
{
int ch;
while (ch = getchar() != EOF);
}

Regards,
Jonathan.

Assuming you put in the remaining parts yourself.

Regards,
Jonathan.
 
J

Jonathan Burd

Jonathan said:
void eat_stdin()
{
int ch;
while (ch = getchar() != EOF);
}

err, make that:

void eat_stdin_line()
{
int ch;
while( (ch = fgetc(stdin)) != EOF && ch != '\n' );
}

Jeez. Sleep dprived.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top