SA-MP Forums Archive
[Ajuda] strcmp bugado - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] strcmp bugado (/showthread.php?tid=604336)



strcmp bugado - bruxo00 - 03.04.2016

Preciso de verificar se duas strings sгo iguais, mas, o strcmp buga (?) e nгo as reconhece como iguais... WTF.

PHP код:
format(stringsizeof(string), "(c:%d) matricula: %s | cInfo[c][Matricula]: %s"cmatriculacInfo[c][Matricula]);
SendClientMessage(playeridCOLOR_CHATstring);
if(
strcmp(matriculacInfo[c][Matricula], true) == 0)
{
    
SendClientMessage(playerid, -1"lol");

Quando as duas variбveis sгo iguais, ex:

PHP код:
        matricula 02-SV-00
        cInfo
[c][Matricula] = 02-SV-00 
O strcmp reconhece como diferente!!! O debug em aзгo:



Como se vк aqui quando c=2 as duas strings ficam iguais, devia enviar a mensagem "lol" mas nгo envia....... Qual serб o problema?


Re: strcmp bugado - F1N4L - 03.04.2016

Entгo nгo sгo iguais! Verifique se realmente sгo pq strcmp nгo falha...

Nгo tem erro, se estб dando diferente й pq de fato й diferente...

@EDIT

Fiz testes e de fato funciona:
(fiz baseado no mais prуximo)

DIFERENTES
PHP код:
new 
        
c,
        
matricula[10] = "02-SV-00",
        
string[129]
    ;
    
enum pMatricula
    
{
        
Matricula[6]
    }
    new 
cInfo[1][pMatricula];
    
cInfo[c][Matricula] = "teste";
    if(
strcmp(matriculacInfo[c][Matricula], true) == 0
    { 
        print(
"iguais");
    } 
    else print(
"diferentes"); 
IGUAIS
PHP код:
new 
        
c,
        
matricula[10] = "02-SV-00",
        
string[129]
    ;
    
enum pMatricula
    
{
        
Matricula[9]
    }
    new 
cInfo[1][pMatricula];
    
cInfo[c][Matricula] = "02-SV-00";
    if(
strcmp(matriculacInfo[c][Matricula], true) == 0
    { 
        print(
"iguais");
    } 
    else print(
"diferentes"); 



Re: strcmp bugado - bruxo00 - 03.04.2016

Mas elas sгo iguais como se pode ver pelo debug...


Re: strcmp bugado - RogerCosta - 03.04.2016

Verifique se na variбvel cInfo[2][pMatricula] o valor dela se nгo tem nenhum espaзo no final da string, por exemplo, o correto seria: "02-SV-00", mas pode estar: "02-SV-00*"

No lugar do * era pra ser um espaзo.


Re: strcmp bugado - F1N4L - 03.04.2016

Quote:
Originally Posted by bruxo00
Посмотреть сообщение
Mas elas sгo iguais como se pode ver pelo debug...
Exato, o que quer dizer q suas strings sгo deferentes... Verifique se o que estб sendo salvo й realmente o que vc postou aki e se essa string estб sendo carregada.

Recomendo usar um comando para visualizar o q tem na string:

PHP код:
CMD:matricula(playerid)
{
format(stringsizeof(string), "(c:%d) matricula: %s | cInfo[c][Matricula]: %s"cmatriculacInfo[c][Matricula]); 
SendClientMessage(playeridCOLOR_CHATstring); 
return 
1;

o que seria o C?
cInfo[c][Matricula]


Re: strcmp bugado - bruxo00 - 03.04.2016

Jб tinha tentado testar o strcmp fora daquela parte do cуdigo em especial e funcionou.

Estive aqui a experimentar vбrias coisas e finalmente acho que descubri o problema... DE ALGUMA FORMA, as strings sгo exactamente iguais (nгo tem espaзos, nem nada disso) mas o tamanho da segunda string й maior () como se pode ver aqui:



Meti as aspas para ter a certeza que nгo havia espaзos. Mas de alguma forma a primeira string tem tamanho 8 e a segunda 16...

EDIT: RESOLVIDO