03.06.2013, 18:40
Hello, i was doing something that doesn't matter and came across a need to convert a string to a integer and backwards, so i made myself these functions:
Then I have some letter and number combination, i extract the letter part. Then, I separate all three characters:
Now the problematic part, I try to increase the int value of Char3 by one and convert it back to a letter:
These are the two prints from above:
The number value of the letter "C" (which i use to test this) is 67 (I checked ASCII), then i add 1 to it, which is 68 and is the letter "D", so where did "DPDC" come from?
I do not see logic in this. Or am I making a mistake somewhere?
pawn Код:
stock StringToInt(str[])
{
new tmp[5];
format(tmp,sizeof(tmp),"%d",str);
return strval(tmp);
}
stock IntToString(int)
{
new tmp[5];
format(tmp,sizeof(tmp),"%s",int);
return tmp;
}
pawn Код:
new Char[2],Char2[2],Char3[2];
strmid(Char,Raides,0,1);
strmid(Char2,Raides,1,2);
strmid(Char3,Raides,2,3);
printf("Pirma:%s Antra:%s Trecia:%s",Char,Char2,Char3);//They are printed correctly.
Now the problematic part, I try to increase the int value of Char3 by one and convert it back to a letter:
pawn Код:
printf("StringToInt Char3:%d",StringToInt(Char3));
new NewChar;
NewChar = StringToInt(Char3);
NewChar++;
printf("NewChar:%s",IntToString(NewChar));
pawn Код:
[21:37:33] StringToInt Char3:67
[21:37:33] NewChar:DPDC
I do not see logic in this. Or am I making a mistake somewhere?