SA-MP Forums Archive
New to pawn, trying to convert some C code to pawn - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: New to pawn, trying to convert some C code to pawn (/showthread.php?tid=124259)



New to pawn, trying to convert some C code to pawn - CHC - 29.01.2010

I'm trying to convert this to pawn but i'm having troubles, its not returning the proper percentage, and doesn't change based on if there are more or less caps, does anyone know whats wrong?

Код:
CHC_IsUpper(ch) {
if(ch>64&&ch<91) return 1;
return 0;
}
//C
float TooManyCaps(char *name) {
int num=0;
char *x=name;
float final;
int size=strlen(name);
while(size--) {
if(CHC_IsUpper(*x++)) num++;
}
final=(float)num/(strlen(name)-1);
return (float)final*100;
}
//PAWN
TooManyCaps(name[]) {

new Float:caps,num,sz;
sz=strlen(name[0]);
while(sz--) {
if(CHC_IsUpper(name[sz])) num++;
}
caps=floatdiv(num,strlen(name[0]));//maybe it will work fine if we don't pass floats..?
caps=floatmul(caps,100);
//caps=(num/(strlen(name[0])-1));
printf("%f!!\n",caps);
if(caps>40) return 1; 
return 0;
}



Re: New to pawn, trying to convert some C code to pawn - CHC - 30.01.2010

so...anyone?


Re: New to pawn, trying to convert some C code to pawn - Dubya - 22.06.2012

pawn Код:
TooManyCaps(name[])
{
    new Float:caps,num,sz;
    sz = strlen(name[0]);
    while(sz--)
    {
        if(CHC_IsUpper(name[sz])) num++;
    }
    caps = floatdiv(num,strlen(name[0]));// You forgot to add spaces. (caps=floatdiv should've been caps = floatdiv, the same with the Line below.
    caps = floatmul(caps,100);
    //caps = (num/(strlen(name[0])-1));
    printf("%f!!\n",caps);
    if(caps>40) return 1;
    return 0;
}