473,394 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

clearerr(stdin) not clear

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[i] = (double) floatarray[i];
}
}}

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
Nov 14 '05 #1
3 2641
"Josh Wilson" <jo***********@duke.edu> wrote in message
news:46**************************@posting.google.c om...
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

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin

Nov 14 '05 #2
jo***********@duke.edu (Josh Wilson) wrote:
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
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #3
"Stephen Sprunk" <st*****@sprunk.org> wrote:
"Josh Wilson" <jo***********@duke.edu> wrote in message
news:46**************************@posting.google. com... <snip>
[...] 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
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: James Hu | last post by:
This program is long. I don't really want to bore everyone with the details, but it handles wierd cases like: /\ * this is a comment *\ / #define FOO ??/* this is not a comment */ char...
6
by: José de Paula | last post by:
I'm writing a little BrainFuck interpreter (by the way, gbf.sourceforge.net) that can read the BrainFuck program from stdin; when the interpreter gets an EOF, it stops reading the BrainFuck program...
24
by: Olaf \El Blanco\ | last post by:
Where is exactly neccesary to put "rewind(stdin)"? After a printf? Before a scanf? I have a lot of problems with strings... If somebody know any good document, please let me know where is... ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
100
by: jacob navia | last post by:
Recently, a heated debate started because of poor mr heathfield was unable to compile a program with // comments. Here is a utility for him, so that he can (at last) compile my programs :-) ...
7
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
9
by: primeSo | last post by:
// FIRST int main(void){ int c, i = 0; char cArray; while( (c = getchar()) != '\n' && c != EOF){ cArray = c; i ++; }
7
by: CaptainnFungi | last post by:
Hi All, I am very new to C and have been working my way through a few C books with the aim of getting more knowledge in programming. However I have hit a wall and I am not sure how to get over it....
30
by: Tarique | last post by:
I have tried to write my custom scanf function on the lines of minprintf provided in K&R2.In the function myscanf() i access memory directly using the address passed to the function .Can it be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.