okay, sorry to keep coming back, but I really can't see what's wrong with my code here.
I have progressed somewhat since my last posts. I have written a program that implements linked lists before, but now with very similar code in this program I can't get it to work. The problem i'm having is with sscanf, I will include the relevant part of my code:
Code:
struct rootnode{
float gauge_diameter;
float gauge_length;
float force;
float extension;
struct node *nextnodeaddr;
} *node1_addr;
node1_addr = malloc( sizeof(struct rootnode) );
fgets( line, sizeof(line), input_stream );
sscanf( line, "%s %lf", null, &node1_addr->gauge_diameter);
printf( "\nread: %s %lf\n", null,
node1_addr->gauge_diameter);
all variables have been declared. line is a character string containing the ascii string:
Gauge_diameter: 20.0e-3 m.
The output on the screen is read: Gauge_diameter: 89128.960938 which is obviously wrong. The thing is, when I use the workaround
Code:
sscanf( line, "%s %lf", null, gauge_diameter);
node1_addr->gauge_diameter=gauge_diameter;
where gauge_diameter is declared as a float, of course, the answer is right, which suggests that the problem is the way the struct is shown to sscanf. Any ideas?
Thanks again