Array duplicate
#1

Hello, I want to write the code that will duplicate the array. Mine code works, but whether there are no bugs?

Код:
enum pItem
{
	hi,
	bye,
	abc[10]
}
new pInfo[2][pItem];

main()
{
	pInfo[0][hi] = 7;
	pInfo[0][bye] = 44;
	format(pInfo[0][abc], 5, "text");
	
	for(new i; pItem:i < pItem; i++) pInfo[1][pItem:i] = pInfo[0][pItem:i];
	printf("hi: %d | bye: %d | abc: %s", pInfo[1][hi], pInfo[1][bye], pInfo[1][abc]);
}
Reply
#2

Yes, you could do it like this.

But you can also set it directly, which would be much faster:

PHP код:
main()
{
    
pInfo[0][hi] = 7;
    
pInfo[0][bye] = 44;
    
format(pInfo[0][abc], 5"text");
    
pInfo[1] = pInfo[0];
    
printf("hi: %d | bye: %d | abc: %s"pInfo[1][hi], pInfo[1][bye], pInfo[1][abc]);

Reply
#3

I didn't know that my variant with preset values doesn't work.
Код:
enum pItem {
	hi = 3,
	bye = 2
}
new pInfo[2][pItem];
Quote:
Originally Posted by ******
Посмотреть сообщение
There's also a memcpy function already.
This is correct code?
Код:
new size = sizeof(pInfo[]);
memcpy(pInfo[1], pInfo[0], 0, size * 4, size);
Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Yes, you could do it like this.

But you can also set it directly, which would be much faster:

PHP код:
main()
{
    
pInfo[0][hi] = 7;
    
pInfo[0][bye] = 44;
    
format(pInfo[0][abc], 5"text");
    
pInfo[1] = pInfo[0];
    
printf("hi: %d | bye: %d | abc: %s"pInfo[1][hi], pInfo[1][bye], pInfo[1][abc]);

Thank you guys.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
I believe so.
Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)