By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

Coping one array to another in Managed C++

P: n/a
How can I copy 5 bytes from the middle of one array to another in Managed C++?
The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
....
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
for(int i=0;i<5;i++)
cBuf[i] = cResult[10+i];

"Steve" <St***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
How can I copy 5 bytes from the middle of one array to another in Managed C++? The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
...
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #2

P: n/a
You could do something like this:

strncpy((unsigned char*)&cBuf[0], ((unsigned char*)&cResult[0])+10, 5);

This should also work IMO.

Martin

Steve wrote:
How can I copy 5 bytes from the middle of one array to another in Managed C++?
The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
...
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #3

P: n/a
Array.Copy?
http://msdn.microsoft.com/library/de...copytopic3.asp

"Steve" <St***@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
How can I copy 5 bytes from the middle of one array to another in Managed
C++?
The following code segment causes the compilation errors below:

unsigned char cResult __gc[] = new unsigned char __gc[256];
unsigned char cBuf __gc[] = new unsigned char __gc[256];
...
strncpy(cBuf, (cResult + 10), 5);

***********************************************

error C2690: '+' : cannot perform pointer arithmetic on a __gc array
error C2664: 'strncpy' : cannot convert parameter 1 from 'unsigned char
__gc[]' to 'char *'
Can only convert a __gc array to or from Object * or Array *

***********************************************

Can anyone clarify this situation, please.

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.