Sscanf reads string in ( )?

Angle is not big enough to hold the input data and thus z is getting overwritten. Try this.

Up vote 2 down vote favorite share g+ share fb share tw.

This question bothers me this few days. I want to read a string for example, input = (-0.001999,-0.919191,-0.777777,999999.999999) using sscanf. And my code is char x10, y10, z10, angle10; sscanf( input+1, "%^,,%^,,%^,,%^)", &x, %y, &z, &angle); printf("%s %s %s %s\n", x, y, z, angle); the expected result is x=-0.001999 y=-0.919191 z=-0.777777 a=999999.999999 but my printf shows : x=-0.001999 y=-0.919191 z=999 a=999999.999999 can somebody help me figure out where the problem is?

Thx! C string sscanf link|improve this question asked Apr 7 '11 at 3:19CLH234.

Angle is not big enough to hold the input data and thus z is getting overwritten. Try this: char x80, y80, z80, angle80.

Thx! Richard! It works!

– CLH Apr 7 '11 at 3:59 You should now accept an answer. – Richard Schneider Apr 7 '11 at 4:00.

After fixing the odd buffer overflow and such, I get: char input = "(-0.001999,-0.919191,-0.777777,999999.999999)"; char x10, y10, z10, angle14; sscanf( input+1, "%9^,,%9^,,%9^,,%13^)", x, y, z, angle); printf("%s %s %s %s\n", x, y, z, angle); and the output I get from this is: -0.001999 -0.919191 -0.777777 999999.999999.

I thought the problem was the sscanf , thanks, Jerry! – CLH Apr 7 '11 at 4:00 +1 for detecting the sscanf arglist fault. – Richard Schneider Apr 7 '11 at 4:01.

Your sscanf like should be sscanf( input+1, "%^,,%^,,%^,,%^)", x, y, z, angle); since your arrays are already pointers (and the y has a % in your example). The other responder has solved the root problem.

Yes, buffer is the root problem , thx, jonsca! – CLH Apr 7 '11 at 3:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions