Help ~
Always help, no way, I am stupid, do not understand all the information to find! You good people, view, give suggestions Caesar ~ save every time I ask questions, heart pull pull cool cool!
NSString * stringToSend = NSStringFromCGPoint (point);
const char * data = [StringToSend UTF8String];
send (CFSocketGetNative (Socket), data, strlen (data) +1,0);
The output side of the form is such that the result: {x, y}
But I want is m_x_y form, I would like to ask, how to convert?
Later, the idea is this:
stringToSend = [NSString stringWithFormat: @ "m_% i_% i", point.x, point.y];
const char * data = [StringToSend UTF8String];
send (CFSocketGetNative (Socket), data, strlen (data) +1, 0);
But this does not get the correct value point is? Why is this?
Reply:
point.x, point.y value on it, stringToSend it?
Reply:
stringToSend = [NSString stringWithFormat: @ "m_% i_% i", point.x, point.y];
Replaced
stringToSend = [NSString stringWithFormat: @ "m_% f_% f", point.x, point.y];
You right-click in xcode CGPoint, select JUMP to defination, you will see one of the two variables X, y is CGFloat type is float, not plastic, so it can not be used in the formatted output% i, and should use% f,
Of course, if you want to format the result is plastic, use a cast,
stringToSend = [NSString stringWithFormat: @ "m_% i_% i", (int) point.x, (int) point.y];
Reply:
Use
stringToSend = [NSString stringWithFormat: @ "m_% f_% f", point.x, point.y];
There will be a "drawback" is automatically filled six decimal places, for example, if x = 10.0, then the output is 10.000000, this might not be what you want, then the f replaced by g, and see the effect, < br />
Reply:
Thank you Ha ~ look at what effect tomorrow
Reply:
Downstairs you should not just say, is% i question, because I have always felt this conversion is correct.
Reply:
is indeed replaced by% g on the line, thank you!
No comments:
Post a Comment