Click here to Skip to main content
15,913,263 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

Is there a method or a way to copy a char array (for example of size 8) in a char array (of size 64).

What I have tried:

I already tried using some methods like Array.Copy and copyto() but it didn't worked.
My result char array was always /0 /0 /0 /0 .....

public int CAN_DefineTransmit(int canNo, int iD, int cycleMs, int offsetMs, int length, char[] frame)
{
    int ret;
    this.ReadBuffer();
    this.CANDIAG_CommandBufferInit();

    this.buff.Param[1].IValue = canNo;
    this.buff.Param[2].IValue = iD;
    this.buff.Param[3].IValue = cycleMs;
    this.buff.Param[4].IValue = offsetMs;
    this.buff.Param[5].IValue = length;
    if ((length < 8 && length >= 0) || length > 8)
    {
        Array.Copy(frame, 0, this.buff.Param[3].FrameFD, 0, length);
    }
    else
    {
        Array.Copy(frame, 0, this.buff.Param[3].FrameFD, 0, 8);
    }

    // this.buff.Param[6].FrameFD = frame;
    ret = this.CANDIAG_Client_SendCommand(501);
    this.WriteBuffer();
    return this.CANDIAG_CommandBufferExit();
}


Frame FD is a char array of 64 declared in a structure.
Posted
Updated 28-Jun-17 21:40pm
v2
Comments
Kornfeld Eliyahu Peter 29-Jun-17 3:26am    
You should show your code...

Try this:
C#
char[] input = "Hello! This is text.".ToCharArray();
char[] output = new char[64];
Array.Copy(input, output, input.Length);
for(int i = 0; i < output.Length; i++)
    {
    char c = output[i];
    Console.WriteLine("{0}:{1:X02}", char.IsControl(c) ? '*' : c, (int)c);
    }
 
Share this answer
 
Comments
Todiruta Costel Nicusor 29-Jun-17 5:23am    
Thank You, it helped me.
OriginalGriff 29-Jun-17 5:32am    
You're welcome!
This example should work fine... Array.copy() copies the range of the source array to the specified array of your choice.
I hope this helps:

C#
char[] myarray = new char[5];
myarray2 = new char[64];
Copy(myarray, myarray2, 5);
 
Share this answer
 
Comments
Todiruta Costel Nicusor 29-Jun-17 5:23am    
Thank You, it helped me.
Prifti Constantine 29-Jun-17 5:32am    
Glad to hear that!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900