How to set string[] to uprercase? -
Azazelo - 12.12.2012
Any function to set string[] to uppercase?
Is there any default funcion for this ?
Re: How to set string[] to uprercase? -
ReneG - 12.12.2012
pawn Код:
stock uppercase(string[])
{
for(new i=0; i<strlen(string); i++)
{
string[i] = toupper(string[i]);
}
return string;
}
Re: How to set string[] to uprercase? -
LarzI - 12.12.2012
Quote:
Originally Posted by ******
Please tell me you didn't do that! You should know better.
|
What would be the optimal to put there, then? I'm just curious.
Re: How to set string[] to uprercase? -
ReneG - 12.12.2012
I could have sworn the compiler gave an indeterminate array size error last time I tried something like this.
Anyways, is this any better?
pawn Код:
stock uppercase(string[])
{
for(new i=0; i<sizeof string; i++)
{
string[i] = toupper(string[i]);
}
return string;
}
Re: How to set string[] to uprercase? -
Azazelo - 12.12.2012
You must spread some Reputation around before giving it to ****** again.
pawn Код:
stock uppercase(string[])
{
for(new i=0; i<(sizeof(string)); i++)
{
string[i] = toupper(string[i]);
}
return string;
}
when i try use "sizeof"
Quote:
indeterminate array size in "sizeof" expression
|
This will do:
pawn Код:
stock uppercase(string[])
{
for(new i=0; i<strlen(string); i++)
{
string[i] = toupper(string[i]);
}
return string;
}
You must spread some Reputation around before giving it to VincentDunn again.
****** Thanks
VincentDunn Thanks
Re: How to set string[] to uprercase? -
LarzI - 12.12.2012
Quote:
Originally Posted by ******
pawn Код:
stock uppercase(string[]) { for(new i = 0, j = strlen(string), i != j; ++i) { string[i] = toupper(string[i]); } }
|
Are you doing ++i just for user preference, or is it actually faster to do that instead of i++ ?
Re: How to set string[] to uprercase? -
Frant1kz - 12.12.2012
Quote:
Originally Posted by ******
I've not actually looked in to the assembly in PAWN because frankly I don't care - if there is any difference it will be basically zero anyway. I do ++i because it is much better practice in C++ (ironically not ++C), as is "!=" rather than "<", and I'm used to thus doing it that way.
|
++C ??
Re: How to set string[] to uprercase? -
ReneG - 13.12.2012
Quote:
Originally Posted by LarzI
Are you doing ++i just for user preference, or is it actually faster to do that instead of i++ ?
|
I highly doubt there is a speed difference, but if there was, the difference would be far beyond human comprehension.
but the differences in code however are as follows.
pawn Код:
main()
{
new
a = 10,
b = 10;
printf("A with pre-increment: %d", ++a);
printf("A after pre-increment: %d", a);
printf("B with post-increment: %d", b++);
printf("B after post-increment: %d", b);
}
prints out
Код:
[18:19:14] A with pre-increment: 11
[18:19:14] A after pre-increment: 11
[18:19:14] B with post-increment: 10
[18:19:14] B after post-increment: 11
++x is basically like adding 1 to the variable before executing the line
x++ is basically like adding 1 to the variable after executing the line