J
Josh Wilson
The fread() is what I believe is having trouble, but I do not know
why. I know that the temp file is created and written to (and w/ the
appropriate amount of data). fread() continues to return 0, but I
don't know why it shouldn't work; but when I used ferror(stdin) and it
gives 0 suggesting to me it read w/o problem, so I'm confused since I
know there is information in the file, and it is allegedly reading
from stdin, any help please?
Thanks!
#define FLOAT 0
#define DOUBLE 6
#define INDIM 32768
#include <stdio.h>
#include <math.h>
main (argc,argv)
int argc;
char **argv;
{
double dfloatarray[INDIM];
float floatarray[INDIM];
int i,istat,iaccum,intype;
int iostat;
float max2=0;
FILE *tempfile;
char s[L_tmpnam];
char *p = tmpnam(s);
if (norm == 1){
iaccum = 0;
tempfile = fopen(p,"a");
while(feof(stdin) == 0){
if (intype == FLOAT) { /*By this time, intype does = FLOAT
*/
istat = fread(floatarray,4,INDIM,stdin);
iaccum+=istat;
for (i=0; i<istat; i++){
dfloatarray = (double) floatarray;
}
}
.....
for(i=0; i<INDIM; i++){
if (dfloatarray > max2){
max2 = dfloatarray;
}
}
for (i=0;i<istat;i++){
floatarray = (float) dfloatarray;
}
iostat=fwrite(floatarray,4,istat,tempfile);
freopen(p,"r",stdin);
}
if (intype == FLOAT)
istat = fread(floatarray,4,INDIM,stdin);
/*This is where it seems to fall apart.*/
fprintf(stderr,"ferror = %d", ferror(stdin));
}
}
why. I know that the temp file is created and written to (and w/ the
appropriate amount of data). fread() continues to return 0, but I
don't know why it shouldn't work; but when I used ferror(stdin) and it
gives 0 suggesting to me it read w/o problem, so I'm confused since I
know there is information in the file, and it is allegedly reading
from stdin, any help please?
Thanks!
#define FLOAT 0
#define DOUBLE 6
#define INDIM 32768
#include <stdio.h>
#include <math.h>
main (argc,argv)
int argc;
char **argv;
{
double dfloatarray[INDIM];
float floatarray[INDIM];
int i,istat,iaccum,intype;
int iostat;
float max2=0;
FILE *tempfile;
char s[L_tmpnam];
char *p = tmpnam(s);
if (norm == 1){
iaccum = 0;
tempfile = fopen(p,"a");
while(feof(stdin) == 0){
if (intype == FLOAT) { /*By this time, intype does = FLOAT
*/
istat = fread(floatarray,4,INDIM,stdin);
iaccum+=istat;
for (i=0; i<istat; i++){
dfloatarray = (double) floatarray;
}
}
.....
for(i=0; i<INDIM; i++){
if (dfloatarray > max2){
max2 = dfloatarray;
}
}
for (i=0;i<istat;i++){
floatarray = (float) dfloatarray;
}
iostat=fwrite(floatarray,4,istat,tempfile);
freopen(p,"r",stdin);
}
if (intype == FLOAT)
istat = fread(floatarray,4,INDIM,stdin);
/*This is where it seems to fall apart.*/
fprintf(stderr,"ferror = %d", ferror(stdin));
}
}