I am new using CAPL. I want to make int array with same value(3). Below is okay.. (No error) However, As you could see this, this is way too complicated and hard to change the array value.
int a[102] =
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3};
I thought this could work but it was not.
int b = 2;
int a[102] = memcpy(a, b, elCount(a));
How can I assign int
array with same value?
Thank you in advance.
There is memcpy
in CAPL similar to memcpy
in C. But memcpy
does not do, what you seem to expect.
memcpy
copies a number of bytes from a certain memory area to your destination. So in order to be able to copy the list of 3
s as in your example, you would need to a have a memory area containing 102 3
s. Which puts you back to start.
Maybe you mean memset
, which does not exist in CAPL.
Why not use a simple for-loop?
int a[102];
for(int i=0; i<elcount(a); i++) {
a[i] = 3;
}
There is only a single place to change the value.
If you want you can even wrap that in a CAPL function and make a
and the value a parameter.