Array to string -
Sickae - 01.04.2015
Hey,
I want to store an array's full content in another variable. I know I can make it by going through every slot but I'm pretty sure there's a much easier way I'm missing out. Please help me!
Re: Array to string -
CalvinC - 01.04.2015
Here's an example:
pawn Код:
new array[2][5]; // Declare the array
array[0] = "Test"; // Make array 0 contain "test"
array[1] = array[0]; // Make array 1 contain what array 0 contains
You cannot store several characters in a single variable if that's what you mean.
Re: Array to string -
Sickae - 01.04.2015
That's what I meant when I said I could go through it slot by slot but I dont want to.
Here's what I want:
Quote:
new Input[5] = {a,b,c,d,e};
new Str = Input
|
But that gives error ofcourse. So basically I want Str to store "abcde".
Re: Array to string -
iggy1 - 01.04.2015
Use functions you can't assign arrays like that in PAWN.
memcpy or
strcat
Re: Array to string -
admantis - 01.04.2015
If you want to insert characters into a string, use
strins.
If you want to copy an array (array2 = array1), use
memcpy.
Respuesta: Array to string -
alexus - 01.04.2015
Код:
new Input[5] = {a,b,c,d,e};
new Str[sizeof(Input)] = Input;
But I don't understand what do you want. You can use index easily for that:
Input[0] = "a"
Input[1] = "b"
Input = "abcde"
Why to copy that you already have?
Re: Respuesta: Array to string -
Yashas - 01.04.2015
Quote:
Originally Posted by alexus
Код:
new Input[5] = {a,b,c,d,e};
new Str[sizeof(Input)] = Input;
But I don't understand what do you want. You can use index easily for that:
Input[0] = "a"
Input[1] = "b"
Input = "abcde"
Why to copy that you already have?
|
Why do you even need that?
new Input = {'a','b','c','d','\0'};
print(Input);
EDIT:Oops sorry, even you were criticizing that :P
Re: Array to string -
CalvinC - 01.04.2015
You can't store several pieces of data in a variable, that's why we use arrays for containing words.
Each variable can store 1 piece of data.
You cannot do
It's the same with arrays, but they're like several variables.
You could say using Array[3] contains 3 "variables".
pawn Код:
Array[0] = "H";
Array[1] = "i";
Array[2] = "\0";
Which is the same as just doing
If the array is declared using
Because each "number" is like 1 variable, so here we have 3 variables, which and can store 1 piece of information each.
The reason we need 3 is because of the null constant, AKA "\0", it tells the compiler that the string ends where the null symbol is.
You can read more in this tutorial:
https://sampforum.blast.hk/showthread.php?tid=318212
Re : Array to string -
nicolaskettler - 01.04.2015
Doing this
pawn Код:
new Input = {'a','b','c','d','e'};
print(Input);
Isn't possible, because this , is supposed to hold an integer generally but doing this is possible:
pawn Код:
new Input[6] = {'a','b','c','d','e'};
print(Input);//would print 'abcde'
//tests:
for(new i = 0; i <6; i++) printf("%d:%s",i,Input);
/*
Would Print:
0:a
1:b
2:c
3:d
4:e
5: ' '//Means an empty message because the fifth cell is for the \0 , the null character
*/
Re: Respuesta: Array to string -
Sickae - 01.04.2015
Quote:
Originally Posted by alexus
Код:
new Input[5] = {a,b,c,d,e};
new Str[sizeof(Input)] = Input;
But I don't understand what do you want. You can use index easily for that:
Input[0] = "a"
Input[1] = "b"
Input = "abcde"
Why to copy that you already have?
|
It was just an example. The data of Input isn't fixed, it's what the user writes in it. To be more specific it's an input styled dialog and I want to use the given input outside of the callback 'OnDialogResponse' so I need a global variable for it. But you already helped me a lot, thanks guys.