sscanf troubles

Might be that eye, at, and up are pointers, so you might need to do something like &((*eye)[0]).
Erm, what happened to the thread?
Sorry, I just deleted the post. Here it is for reference:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>

float* algVector( float x, float y, float z, float w ) 
{
	float* v = new float[4];
	v[0] = x;
	v[1] = y;
	v[2] = z;
	v[3] = w;
	return v;
}

int main()
{
	float* eye = algVector( 0,0,0,1 );
	float* at = algVector( 0,0,0,1 );
	float* up = algVector( 0,0,0,1 );
	float fovy;
	float nearp;
	float farp;
	int screenWidth;
	int screenHeight;
	char buffer[512] = "CAMERA 0. 1. 5. 0. 0. 0.  0. 1. 1.   100. 1. 100. 400 400\n";
	printf("%d",sscanf( buffer, "CAMERA %1f %1f %1f %1f %1f %1f %1f %1f %1f %1f %1f %1f %d %d\n", &eye[0], &eye[1], &eye[2], &at[0], &at[1], &at[2], &up[0], &up[1], &up[2], &fovy, &nearp, &farp, &screenWidth, &screenHeight ));
	printf("CAMERA %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %d %d\n",eye[0],eye[1],eye[2],at[0],at[1],at[2],up[0],up[1],up[2],fovy,nearp,farp,screenWidth,screenHeight );
	delete[] eye;
	delete[] at;
	delete[] up;
	return 0;
}


The following code, for whatever reason, has sscanf fail. It returns 14, which implies success, however all the float variables have their values set to 0 instead of the correct values.

I deleted it because I solved it two seconds after posting it. For whatever reason, asking for sscanf to catch floats listed without decimal digits using %1f fails. Change it to the default %f and it works just fine.
Last edited on
The ampersands aren't needed on the arguments in the sscanf call.
Yes they are. Without them, you're simply sending a copy of the value of (float)eye[0], not a pointer to the actual value of (float*)&eye[0].
Oohh, oops, i didn't pay enough attention to notice they were pointers.
Okay, that didn't solve it. I substituted the %1f's in my original code for the simple %f, but it's still bugging out. In this case, it must be throwing an exception or something because the entire function gets thrown out. I use the debugger to go through the steps, but when I go through the sscanf call, the entire function seems to fail, since the focus returns to the GUI. If I want to, I can even access this function again (only to see it fail again, of course).
Topic archived. No new replies allowed.