主题:一个关于接收ip地址时候出现的问题
void __fastcall TForm1::CheckBanben(int num,int Address,byte array[])
{
String str="";
str=str+array[Address+1]+".";
str=str+array[Address+2]+".";
str=str+array[Address+3]+"."; 、
str=str+array[Address+4];
Memo1->Lines->Add(str) ;
上面这样写我可以读到正确的ip:192.168.0.236
问题1:
如果是
String str="";
str=array[Address+1]+".";//这句变化
str=str+array[Address+2]+".";
str=str+array[Address+3]+"."; 、
str=str+array[Address+4];
Memo1->Lines->Add(str) ;
为什么会出现8v@168.0.236这样的乱码?
问题2:
如果是
str=array[Address+1]+".";//四句都变化
str+=array[Address+2]+".";
str+=array[Address+3]+".";
str+=array[Address+4];
Memo1->Lines->Add(str) ;
为什么会出现.236(前面只剩下若干空格)
}
调用上述的函数
void __fastcall TForm1::banben(byte ReBuf[],int len)
{
String str="";
for(int i=6;i <len-1;i++)
{
AnsiString TempStr="0x"+IntToHex(ReBuf[i],2) ;
str+= AnsiString((char)(TempStr. ToInt()));
if(IntToHex(ReBuf[i],2)=="5C")
{
CheckBanben(ReBuf[i+1],i+1,ReBuf);
}
}
}