[Solved] Country help
#1

Hey,
I'm trying to compare this:
pawn Код:
new country[64];
GetPlayerCountry(playerid,country);
printf("COUNTRY: %s",country); //prints "COUNTRY: Lithuania"
if(!strcmp(country,"Lithuania")) //should return 0 because strings are the same
{

//[some code which is not being executed]

}
printf("STRCMP COUNTRY: %i",strcmp(country,"Lithuania")); //prints 2, so that means strcmp returns 2 instead of 0 (- strings are the same)
Where's the problem? :O
Reply
#2

Quote:
Originally Posted by SiJ
Hey,
I'm trying to compare this:
pawn Код:
new country[64];
GetPlayerCountry(playerid,country);
printf("COUNTRY: %s",country); //prints "COUNTRY: Lithuania"
if(!strcmp(country,"Lithuania")) //should return 0 because strings are the same
{

//[some code which is not being executed]

}
printf("STRCMP COUNTRY: %i",strcmp(country,"Lithuania")); //prints 2, so that means strcmp returns 2 instead of 0 (- strings are the same)
Where's the problem? :O
Would be cewl if you could tell me what problem occurs

#EDIT#: Okay, i got it. Sry didn't read it to the end :/
Reply
#3

Quote:
Originally Posted by DeathOnaStick
Quote:
Originally Posted by SiJ
Hey,
I'm trying to compare this:
pawn Код:
new country[64];
GetPlayerCountry(playerid,country);
printf("COUNTRY: %s",country); //prints "COUNTRY: Lithuania"
if(!strcmp(country,"Lithuania")) //should return 0 because strings are the same
{

//[some code which is not being executed]

}
printf("STRCMP COUNTRY: %i",strcmp(country,"Lithuania")); //prints 2, so that means strcmp returns 2 instead of 0 (- strings are the same)
Where's the problem? :O
Would be cewl if you could tell me what problem occurs
-.-' next time read the code comments too..

strcmp(country,"Lithuania") returns 2 instead of returning 0.. country is "Lithuania".. so why strcmp("Lithuania","Lithuania") returns 2 and not 0
Reply
#4

I don't see a problem here, but it might be one of those:

1. Big Letters, Small Letters. I don't know if the default value of the ignorecase is "true" or "false", try adding it.
2. Maybe you've got a space, e.g. at the beginning or the end of the country string.
3. Maybe you've got a problem in GetPlayerCountry.

ACTUALLY the most is not possible, because it prints "Lithuania" correct.

Try this, if you didn't before. It actually does same, as yours does, but maybe you just try .

pawn Код:
if(strcmp(country,"Lithuania",true,sizeof(country))==0)
Any other ideas i can't give from my side, it all looks okay to me...

Cheerz
Reply
#5

Ok.. I found the problem:
This:
Код:
printf("|%s|",country);
Prints:
Quote:

|Lithuania

|

Instead of |Lithuania|

Any ideas why?
Here's GetPlayerCountry function:

pawn Код:
GetParams(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(Params[0],sizeof(Params),"");
    format(Params[1],sizeof(Params),"");
    format(Params[2],sizeof(Params),"");
    format(Params[3],sizeof(Params),"");

    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,".",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(Params[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}


GetFileData(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(FileData[0],sizeof(FileData),"");
    format(FileData[1],sizeof(FileData),"");
    format(FileData[2],sizeof(FileData),"");
    format(FileData[3],sizeof(FileData),"");
    format(FileData[4],sizeof(FileData),"");
    format(FileData[5],sizeof(FileData),"");
    format(FileData[6],sizeof(FileData),"");
    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,",",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(FileData[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}

GetPlayerCountry(playerid,Country[120]){
    new IPAddress[256];
    new a,b,c,d,ipf;
    new File:IPFile;
    new Text[256],start,end;
    GetPlayerIp(playerid,IPAddress,sizeof(IPAddress));
    GetParams(IPAddress);
    a=strval(Params[0]);
    b=strval(Params[1]);
    c=strval(Params[2]);
    d=strval(Params[3]);
    if(a==127 && b==0 && c==0 && d==1){
        format(Country,sizeof(Country),"Unknown");
        return 1;
    }
    ipf = (16777216*a) + (65536*b) + (256*c) + d;
    if(!fexist("CountriesIPs/IPLIST.csv")) return SendClientMessage(playerid,0xFF0000FF,"File not found");
    IPFile=fopen("CountriesIPs/IPLIST.csv",io_read);
    fread(IPFile,Text,sizeof(Text),false);
    while(strlen(Text)>0){
      GetFileData(Text);
      start=strval(FileData[0]);
      end=strval(FileData[1]);
      if(ipf>=start && ipf<=end){
            format(Country,sizeof(Country),"%s",FileData[6]);
            fclose(IPFile);
            return 1;
      }
      fread(IPFile,Text,sizeof(Text),false);
    }
    fclose(IPFile);
    return 1;
}
EDIT: 800 posts!
Reply
#6

Quote:
Originally Posted by SiJ
Ok.. I found the problem:
This:
Код:
printf("|%s|",country);
Prints:
Quote:

|Lithuania

|

Instead of |Lithuania|

Any ideas why?
Here's GetPlayerCountry function:

pawn Код:
GetParams(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(Params[0],sizeof(Params),"");
    format(Params[1],sizeof(Params),"");
    format(Params[2],sizeof(Params),"");
    format(Params[3],sizeof(Params),"");

    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,".",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(Params[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}


GetFileData(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(FileData[0],sizeof(FileData),"");
    format(FileData[1],sizeof(FileData),"");
    format(FileData[2],sizeof(FileData),"");
    format(FileData[3],sizeof(FileData),"");
    format(FileData[4],sizeof(FileData),"");
    format(FileData[5],sizeof(FileData),"");
    format(FileData[6],sizeof(FileData),"");
    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,",",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(FileData[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}

GetPlayerCountry(playerid,Country[120]){
    new IPAddress[256];
    new a,b,c,d,ipf;
    new File:IPFile;
    new Text[256],start,end;
    GetPlayerIp(playerid,IPAddress,sizeof(IPAddress));
    GetParams(IPAddress);
    a=strval(Params[0]);
    b=strval(Params[1]);
    c=strval(Params[2]);
    d=strval(Params[3]);
    if(a==127 && b==0 && c==0 && d==1){
        format(Country,sizeof(Country),"Unknown");
        return 1;
    }
    ipf = (16777216*a) + (65536*b) + (256*c) + d;
    if(!fexist("CountriesIPs/IPLIST.csv")) return SendClientMessage(playerid,0xFF0000FF,"File not found");
    IPFile=fopen("CountriesIPs/IPLIST.csv",io_read);
    fread(IPFile,Text,sizeof(Text),false);
    while(strlen(Text)>0){
      GetFileData(Text);
      start=strval(FileData[0]);
      end=strval(FileData[1]);
      if(ipf>=start && ipf<=end){
            format(Country,sizeof(Country),"%s",FileData[6]);
            fclose(IPFile);
            return 1;
      }
      fread(IPFile,Text,sizeof(Text),false);
    }
    fclose(IPFile);
    return 1;
}
EDIT: 800 posts!
1.: Gz for the 800
2.: I guess the problem is located in the file, you read the countries from. "Filedata[6]", or whatever you read from, might contain a space (i mean there begins a new line, dunno how its called in english ). Whatever... When it prints it like you said, the problem should be located there.

Cheerz
Reply
#7

Quote:
Originally Posted by DeathOnaStick
Quote:
Originally Posted by SiJ
Ok.. I found the problem:
This:
Код:
printf("|%s|",country);
Prints:
Quote:

|Lithuania

|

Instead of |Lithuania|

Any ideas why?
Here's GetPlayerCountry function:

pawn Код:
GetParams(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(Params[0],sizeof(Params),"");
    format(Params[1],sizeof(Params),"");
    format(Params[2],sizeof(Params),"");
    format(Params[3],sizeof(Params),"");

    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,".",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(Params[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}


GetFileData(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(FileData[0],sizeof(FileData),"");
    format(FileData[1],sizeof(FileData),"");
    format(FileData[2],sizeof(FileData),"");
    format(FileData[3],sizeof(FileData),"");
    format(FileData[4],sizeof(FileData),"");
    format(FileData[5],sizeof(FileData),"");
    format(FileData[6],sizeof(FileData),"");
    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,",",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(FileData[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}

GetPlayerCountry(playerid,Country[120]){
    new IPAddress[256];
    new a,b,c,d,ipf;
    new File:IPFile;
    new Text[256],start,end;
    GetPlayerIp(playerid,IPAddress,sizeof(IPAddress));
    GetParams(IPAddress);
    a=strval(Params[0]);
    b=strval(Params[1]);
    c=strval(Params[2]);
    d=strval(Params[3]);
    if(a==127 && b==0 && c==0 && d==1){
        format(Country,sizeof(Country),"Unknown");
        return 1;
    }
    ipf = (16777216*a) + (65536*b) + (256*c) + d;
    if(!fexist("CountriesIPs/IPLIST.csv")) return SendClientMessage(playerid,0xFF0000FF,"File not found");
    IPFile=fopen("CountriesIPs/IPLIST.csv",io_read);
    fread(IPFile,Text,sizeof(Text),false);
    while(strlen(Text)>0){
      GetFileData(Text);
      start=strval(FileData[0]);
      end=strval(FileData[1]);
      if(ipf>=start && ipf<=end){
            format(Country,sizeof(Country),"%s",FileData[6]);
            fclose(IPFile);
            return 1;
      }
      fread(IPFile,Text,sizeof(Text),false);
    }
    fclose(IPFile);
    return 1;
}
EDIT: 800 posts!
1.: Gz for the 800
2.: I guess the problem is located in the file, you read the countries from. "Filedata[6]", or whatever you read from, might contain a space (i mean there begins a new line, dunno how its called in english ). Whatever... When it prints it like you said, the problem should be located there.

Cheerz
Nope.. Line in the file is without spaces:
Quote:

1045487616,1045495807,ripencc,1036713600,LT,LTU,Li thuania

Maybe I'll use strfind instead of strcmp..
Thanks for help
Reply
#8

Quote:
Originally Posted by SiJ
Quote:
Originally Posted by DeathOnaStick
Quote:
Originally Posted by SiJ
Ok.. I found the problem:
This:
Код:
printf("|%s|",country);
Prints:
Quote:

|Lithuania

|

Instead of |Lithuania|

Any ideas why?
Here's GetPlayerCountry function:

pawn Код:
GetParams(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(Params[0],sizeof(Params),"");
    format(Params[1],sizeof(Params),"");
    format(Params[2],sizeof(Params),"");
    format(Params[3],sizeof(Params),"");

    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,".",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(Params[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}


GetFileData(Source[]){
    new Destination[256];
    new SLen=strlen(Source);
    new at,pos=0,tp=0;
    new tempo[256];

    ////////////// Clearing DATA /////////////////  FOR LOOP WAS NOT WORKING FOR THIS PURPOSE
    format(FileData[0],sizeof(FileData),"");
    format(FileData[1],sizeof(FileData),"");
    format(FileData[2],sizeof(FileData),"");
    format(FileData[3],sizeof(FileData),"");
    format(FileData[4],sizeof(FileData),"");
    format(FileData[5],sizeof(FileData),"");
    format(FileData[6],sizeof(FileData),"");
    /////////////////////////////////////////////

    for(at=pos;at<=SLen;at++){
        strmid(tempo,Source,at,at+1,sizeof(tempo));
        if(!strcmp(tempo,",",true)){
            if(tp<=10){
                strmid(Destination,Source,pos,at,sizeof(Destination));
                format(FileData[tp][0],256,"%s",Destination);
                tp=tp+1;
            }
            pos=at+1;
        }
    }
    return 1;
}

GetPlayerCountry(playerid,Country[120]){
    new IPAddress[256];
    new a,b,c,d,ipf;
    new File:IPFile;
    new Text[256],start,end;
    GetPlayerIp(playerid,IPAddress,sizeof(IPAddress));
    GetParams(IPAddress);
    a=strval(Params[0]);
    b=strval(Params[1]);
    c=strval(Params[2]);
    d=strval(Params[3]);
    if(a==127 && b==0 && c==0 && d==1){
        format(Country,sizeof(Country),"Unknown");
        return 1;
    }
    ipf = (16777216*a) + (65536*b) + (256*c) + d;
    if(!fexist("CountriesIPs/IPLIST.csv")) return SendClientMessage(playerid,0xFF0000FF,"File not found");
    IPFile=fopen("CountriesIPs/IPLIST.csv",io_read);
    fread(IPFile,Text,sizeof(Text),false);
    while(strlen(Text)>0){
      GetFileData(Text);
      start=strval(FileData[0]);
      end=strval(FileData[1]);
      if(ipf>=start && ipf<=end){
            format(Country,sizeof(Country),"%s",FileData[6]);
            fclose(IPFile);
            return 1;
      }
      fread(IPFile,Text,sizeof(Text),false);
    }
    fclose(IPFile);
    return 1;
}
EDIT: 800 posts!
1.: Gz for the 800
2.: I guess the problem is located in the file, you read the countries from. "Filedata[6]", or whatever you read from, might contain a space (i mean there begins a new line, dunno how its called in english ). Whatever... When it prints it like you said, the problem should be located there.

Cheerz
Nope.. Line in the file is without spaces:
Quote:

1045487616,1045495807,ripencc,1036713600,LT,LTU,Li thuania

Maybe I'll use strfind instead of strcmp..
Thanks for help
Yea, but anyway, there must be a real sollution... I'm still thinking
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)