clearerr(stdin) not clear

J

Josh Wilson

OK, somewhat new to C, have searched the group and haven't found an
answer that has fixed my problem, so I am just going to try posting
it.

I am taking really large image files(128x128x35) and turning them into
float, short, double, etc. files, writing them to an array in sections
(so that the machine is working w/ smaller arrays), changing or
evaluating the pixel values, and them writing them out. Doing this
before, I could only find out information as I was doing the
processing, now I want to evaluate all the pixel information, and then
do the manipulations. So, I have a do-while w/ an fread, which
procedes as long as (feof(stdin) == 0)... (in that loop I collected my
info, min., max., etc.) Now, I want to go back and do the whole thing
over as before, putting the values into the array and manipulate them,
so I just clearerr(stdin) and it should be willing to read the file
stream all over again, right?


if(feof(stdin)) clearerr(stdin);
iaccum = 0;
{
if (intype == FLOAT) {
fread(floatarray,4,INDIM,stdin);
istat= fread(floatarray,4,INDIM,stdin);
iaccum+=istat;
for (i=0; i<istat; i++){
dfloatarray = (double) floatarray;
}
}}

Putting in test print outs before, "iaccum+=stat" tells me istat is
still 0, but it should be around 32000. So for my fread function,
floatarray was initialized w/ a size of [INDIM], I'm writing in floats
4 bytes long, there are INDIM items in the array, and stdin has been
cleared... any thoughts why istat isn't changing?
Thanks all for your time!

JMW
 
S

Stephen Sprunk

Josh Wilson said:
OK, somewhat new to C, have searched the group and haven't found an
answer that has fixed my problem, so I am just going to try posting
it.

I am taking really large image files(128x128x35) and turning them into
float, short, double, etc. files, writing them to an array in sections
(so that the machine is working w/ smaller arrays), changing or
evaluating the pixel values, and them writing them out. Doing this
before, I could only find out information as I was doing the
processing, now I want to evaluate all the pixel information, and then
do the manipulations. So, I have a do-while w/ an fread, which
procedes as long as (feof(stdin) == 0)... (in that loop I collected my
info, min., max., etc.) Now, I want to go back and do the whole thing
over as before, putting the values into the array and manipulate them,
so I just clearerr(stdin) and it should be willing to read the file
stream all over again, right?

clearerr() will reset the status reported by feof() and ferror(), but it
alter where you're reading from in the stream. Are you looking for lseek(),
perhaps?

S
 
I

Irrwahn Grausewitz

OK, somewhat new to C, have searched the group and haven't found an
answer that has fixed my problem, so I am just going to try posting
it.

I am taking really large image files(128x128x35) and turning them into
float, short, double, etc. files, writing them to an array in sections
(so that the machine is working w/ smaller arrays), changing or
evaluating the pixel values, and them writing them out. Doing this
before, I could only find out information as I was doing the
processing, now I want to evaluate all the pixel information, and then
do the manipulations. So, I have a do-while w/ an fread, which
procedes as long as (feof(stdin) == 0)... (in that loop I collected my
info, min., max., etc.) Now, I want to go back and do the whole thing
over as before, putting the values into the array and manipulate them,
so I just clearerr(stdin) and it should be willing to read the file
stream all over again, right?
<snip>

Nope. You're certainly looking for

fseek( stdin, 0, SEEK_SET ) /* set position to beginning */

or

rewind( stdin ) /* same as above, plus reset error indicator */

respectively. However, both constructs will only work as expected
when the stream designated by stdin is associated with a 'real' file,
for obvious reasons (though it sometimes would be nice to be able to
rewind the user from within a program ;-).

Regards
 
I

Irrwahn Grausewitz

Stephen Sprunk said:
[...] Now, I want to go back and do the whole thing
over as before, putting the values into the array and manipulate them,
so I just clearerr(stdin) and it should be willing to read the file
stream all over again, right?

clearerr() will reset the status reported by feof() and ferror(), but it
alter where you're reading from in the stream.

ITYM: ... won't alter ...
Are you looking for lseek(),
perhaps?

Nope. No lseek function in standard C. He wants fseek or rewind.

Regards
 

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

Similar Threads


Members online

Forum statistics

Threads
473,961
Messages
2,570,130
Members
46,689
Latest member
liammiller

Latest Threads

Top