|
You mean like this,
::memcpy(&tmpBuffer[0], &iReq, 4);
::memcpy(&tmpBuffer[4], &strGetName, 6);
Great.........
I appreciate your help all the time...
Eranga
|
|
|
|
|
a good idea would be to use sizeof, ie:
::memcpy(&tmpBuffer[0], &iReq, 4);<br />
::memcpy(&tmpBuffer[sizeof(int)], &strGetName, 6);
|
|
|
|
|
Haroon Sarwar wrote: a good idea would be to use sizeof, ie:
::memcpy(&tmpBuffer[0], &iReq, 4);
::memcpy(&tmpBuffer[sizeof(int)], &strGetName, 6);
Refined as below:
memcpy(&tmpBuffer[0], &iReq, sizeof(int) );
memcpy(&tmpBuffer[0 + sizeof(int)], &strGetname, 6);
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: Refined as below:
memcpy(&tmpBuffer[0], &iReq, sizeof(int) );
memcpy(&tmpBuffer[0 + sizeof(int)], &strGetname, 6);
Further refined as
memcpy(&tmpBuffer[0], &iReq, sizeof(iReq) );
memcpy(&tmpBuffer[0 + sizeof(iReq)], &strGetname, 6);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: Further refined as
memcpy(&tmpBuffer[0], &iReq, sizeof(iReq) );
memcpy(&tmpBuffer[0 + sizeof(iReq)], &strGetname, 6);
Even more:
char* tmpBuffer = new char[sizeof(iReq) + strlen(strGetName)];
memcpy(&tmpBuffer[0], &iReq, sizeof(iReq) );
memcpy(&tmpBuffer[0 + sizeof(iReq)], &strGetName, strlen(strGetName) );
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: Even more:
char* tmpBuffer = new char[sizeof(iReq) + strlen(strGetName)];
memcpy(&tmpBuffer[0], &iReq, sizeof(iReq) );
memcpy(&tmpBuffer[0 + sizeof(iReq)], &strGetName, strlen(strGetName) );
still, it's not the state of art :
char* tmpBuffer = new char[sizeof(iReq) + strlen(strGetName)];
if (tmpBuffer)
{
memcpy(&tmpBuffer[0], &iReq, sizeof(iReq) );
memcpy(&tmpBuffer[0 + sizeof(iReq)], &strGetName, strlen(strGetName) );
}
...
...
if (tmpBuffer) delete [] tmpBuffer;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
|
Why is that. I know that sizeof(int) also gives the number 4. But why I can't use number 4 directly. Any special reason.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Why is that. I know that sizeof(int) also gives the number 4. But why I can't use number 4 directly. Any special reason.
If you are coding 16-bit applications, sizeof(int) = 2.
16-bit DOS / Windows
sizeof int: 2
32-bit Windows
sizeof int: 4
64-bit Windows
sizeof int: 4
Maxwell Chen
|
|
|
|
|
eg. if you are porting your app to 64 bit machine somewhere in the future the size of an integer will be 8, and you will have to change 4 to 8 in the code to ensure it works correctly...using sizeof ensures no such change will need to be made...
|
|
|
|
|
Eranga Thennakoon wrote: ::memcpy(tmpBuffer, &iReq, 4);
::memcpy(tmpBuffer, &strGetName, 6);
These two statements are writing to the same location. The second one needs to write four bytes past the starting address of tmpBuffer , like.
memcpy(tmpBuffer, &iReq, 4);
memcpy(tmpBuffer+4, strGetName, 6);
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes my code overwriting the buffer. Any way pointing the buffer make correction to me, as on my second post. It is ok, right....
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Any way pointing the buffer make correction to me, as on my second post. It is ok, right....
I've no idea what you are saying here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am porting bc3.1 code to VC++.Net. While compiling i am getting the above error in the below line
extern char MC_320_ATP[];
this is in header file and the cpp file contains
char MC_320_ATP[] = "\n#DIR A320\n 4.2 Micro Computer Test %02d.%02d.%04d %02d:%
02d:%02d";
Thanks for your help
Regards
|
|
|
|
|
subramanyeswari wrote: "\n#DIR A320\n 4.2 Micro Computer Test %02d.%02d.%04d %02d:%
is there a specific reason that there is a newline after this? or has is just been introduced while pasting the code here?
|
|
|
|
|
For the newline only. It is not from the copy and paste.
|
|
|
|
|
in that case can try removing it or putting a \ at the end, ie:
char MC_320_ATP[] = "\n#DIR A320\n 4.2 Micro Computer Test %02d.%02d.%04d %02d:% \<br />
02d:%02d";
|
|
|
|
|
I tried both. It didn't work
|
|
|
|
|
It is showing error in the header file not in the cpp file
|
|
|
|
|
then the error probably lies in the lines above extern char MC_320_ATP[]; , check those...
|
|
|
|
|
Hello,
extern const char* MC_320_ATP[]
const char* MC_320_ATP[]
Hope this helps.
Bekir.
|
|
|
|
|
this also didn't work. Any other solutions
|
|
|
|
|
If the error is happening in the .H file, then the string won;t matter. But the new line rings alarm bells for me. Try making sure all the text is on one line.
Also try using
extern const char *MC_320_API;
instead.
(Both those have been suggested).
Also suggested, but I haven't seen you reply to it...
The problem might not even be on that line of code - it could be higher.
Try commenting out the line, and see if the problem goes away, or if it moves to the next line.
If it moves, then the problem was "bad" code higher up.
(and yes, if you comment out the extern, you will have errors in your cpp files - this is just a test).
Iain.
|
|
|
|
|
thank you all. I figured it out. I missed a semi colon in the previous included header file.
Regards
|
|
|
|
|
I would like to build a list control with first column used as a “horizontal header"”.
With the first column locked in place the rest of the columns should scroll horizontally as in "standard" list control.
Any suggestions how to do this?
Thanks for reading
Cheers
Vaclav
|
|
|
|