PDA

View Full Version : New to pawn, trying to convert some C code to pawn


CHC
29/01/2010, 07:18 PM
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;
}

CHC
30/01/2010, 07:37 PM
so...anyone?

Dubya
22/06/2012, 05:09 AM
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;
}