zazula@uazhe0.physics.arizona.edu (RALPH ZAZULA) (04/13/91)
Arg!! I'm pulling my hair out!!!!
I have this code that *was* working but now, all of the sudden, it
has stopped working. It is so trivial, I can't see what other coding
I could have done that would cause it to fail. Here is a fragment
represeting what I'm trying to do:
double d;
int i;
char str[255];
FILE *infile;
/* infile opened */
while (EOF != fscanf(infile,"%1s",str))
switch(str[0]) {
case 'I' :
fscanf(infile,"%d",&i);
printf("i: %d\n",i);
fgets(str,255,infile); /* flush the line */
break;
case 'D' :
fscanf(infile,"%f",&d);
printf("d: %f\n",d);
fgets(str,255,infile); /* flush the line */
break;
default :
exit(0);
}
This code is applied to an input file such as:
I 5
D 0.1
The output I get is:
I 5
D 0.000000
*W*H*Y*????? It was giving correct output yesterday... How do
I go about trying to see where the fscanf is failing? This is the
first code to get executed in my program...
Please help, I'm going wacko (ha ha, hee hee...)
Ralph
|----------------------------------------------------------------------|
| Ralph Zazula "Computer Addict!" |
| University of Arizona --- Department of Physics |
| UAZHEP::ZAZULA (DecNet/HEPNet) |
| zazula@uazhe0.physics.arizona.edu (Internet) |
|----------------------------------------------------------------------|
| "You can twist perceptions, reality won't budge." - Neil Peart |
|----------------------------------------------------------------------|zazula@uazhe0.physics.arizona.edu (RALPH ZAZULA) (04/13/91)
Thanks to all who replied!! The problem was that I was using the format "%f" for double instead of "%F". What added to the confusion is that the VAX/VMS machine I was working on at the start didn't mind that I mixed %f and double. I moved the code to the NeXT when I came home from school yesterday and did about 2 hours more work on it before I looked at the output again. I was sure I coded something that trashed the file reading... Back to neural-net land, Ralph |----------------------------------------------------------------------| | Ralph Zazula "Computer Addict!" | | University of Arizona --- Department of Physics | | UAZHEP::ZAZULA (DecNet/HEPNet) | | zazula@uazhe0.physics.arizona.edu (Internet) | |----------------------------------------------------------------------| | "You can twist perceptions, reality won't budge." - Neil Peart | |----------------------------------------------------------------------|
adonis1@nwnexus.WA.COM (Adonis Corporation ) (04/16/91)
In article <1991Apr12.121245.518@arizona.edu> zazula@uazhe0.physics.arizona.edu writes: > > > double d; Use %lf to write/read doubles. Doug Kent Independent NeXT Developer > case 'D' : > fscanf(infile,"%f",&d); > printf("d: %f\n",d); > fgets(str,255,infile); /* flush the line */ > break;