Original Post
Hi guys,
I'm trying to send a sequence of floats over the network and here are several steps that I am following:
I'm stuck at step (1): converting an float to a string. I'm using sprintf to do that (I've also tried with sprintf_s) but it doesn't work.
Error msg:
[bquote]
Unhandled exception at 0x00412fd0 in hybrid-rendering.exe: 0xC0000005: Access violation reading location 0x00000000.
[/bquote]
I know that it's pretty unsafe when using sprintf as we don't know the size of data in advance. So is there any alternative ways to do that sort of things? if someone knows how to fix this, please share with me, I will really appreaciate your help.
Thanks,
Dong
I'm trying to send a sequence of floats over the network and here are several steps that I am following:
- Convert a float to a string (or char*)
- send the string to the client (using socket
- Repeat (1), (2) till the last float
I'm stuck at step (1): converting an float to a string. I'm using sprintf to do that (I've also tried with sprintf_s) but it doesn't work.
float bufferData[] = {
5.81414, 5.49492, 3.87633,
6.58321, 4.59523, 4.4363,
6.54791, 4.60198, 4.43473,
5.81414, 5.49492, 3.87633,
//.........
//.........
6.54791, 4.60198, 4.43473,
6.01867, 4.9006, 4.2733,
5.81414, 5.49492, 3.87633,
};
int N = sizeof(bufferData)/sizeof(float);
for (int i = 0; i < N; i++)
{
sprintf(buf, "%f", bufferData);
//send buf to the client
}
Error msg:
[bquote]
Unhandled exception at 0x00412fd0 in hybrid-rendering.exe: 0xC0000005: Access violation reading location 0x00000000.
[/bquote]
I know that it's pretty unsafe when using sprintf as we don't know the size of data in advance. So is there any alternative ways to do that sort of things? if someone knows how to fix this, please share with me, I will really appreaciate your help.
Thanks,
Dong