How to set string[] to uprercase?
#1

Any function to set string[] to uppercase?


Is there any default funcion for this ?
Reply
#2

pawn Код:
stock uppercase(string[])
{
    for(new i=0; i<strlen(string); i++)
    {
        string[i] = toupper(string[i]);
    }
    return string;
}
Reply
#3

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.
Reply
#4

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;
}
Reply
#5

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
Reply
#6

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++ ?
Reply
#7

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 ??
Reply
#8

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)