Array question
#1

Does pawn string functions use char pointer as start point?
I can explain more clearly, but I'm not sure if anyone will EVER respond to my threads.
Reply
#2

please explain what you mean. im bored and i need some addiction
Reply
#3

On pawn forum
It means that you can provide just a starting point of something, for example you have a string full of values, and you know for example, where is an float value, so far it seems, that to get it you need just to floatvar(cmdtext[firstchar]) which you can for example refine from command lenght + 2 (actually for floats +1 or +3 fits aswell, haven't tested strval so much) which yields me a much easier life being C++.
Example old style command could be as follows:
pawn Код:
if (!strcmp(cmdtext, "/gravity "))
{
    gravity=floatvar(cmdtext[9]);
}
Which would give an:
INPUT /gravity 0.006
OUTPUT 0.006 (as a float)
And as i said, for floats, you can target either the 8th character (In example it's a whitespace) 9th character (It's 0) and even 10th character (It's a dot)

Just for real saying, otherwise you would need to subtract the remains of the string - somewhat like this:
new string;
strmid(<forgot params as i don't use it >);
floatvar(string);
Well I'm quite sure, that my version is faster in the right context.
Reply
#4

You're correct in your presumption.

Example code:
pawn Код:
new chararray[50]="I like toast";
printf("%s",chararray[2]); //Gives output 'like toast'
printf("%s",chararray[sizeof("I like ")]); //Gives output 'toast'
(I'm not quite sure if the first one has to be 2 or 1, you would need to try)


I hope this helped you.
Reply
#5

Yeah, the main "problem" is that this is how CHAR* works, so anyway, no shit, but pawn has pointers. Otherwise than the maker has stated.
Reply
#6

Quote from pawn langpdf
Quote:

C language functions can pass “output values” via pointer arguments. The
standard function scanf, for example, stores the values or strings that it
reads from the console into its arguments. You can design a function in
C so that it optionally returns a value through a pointer argument; if the
caller of the function does not care for the return value, it passes NULL as the
pointer value. The standard function strtol is an example of a function that
does this. This technique frequently saves you from declaring and passing
dummy variables. pawn replaces pointers with references, but references
cannot be NULL. Thus, pawn needed a different technique to “drop” the
values that a function returns via references. Its solution is the use of an
“argument placeholder” that is written as an underscore character (“ ”);
Prolog programmers will recognize it as a similar feature in that language.
The argument placeholder reserves a temporary anonymous data object (a
“cell” or an array of cells) that is automatically destroyed after the function
call.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)