The code is,
Unsigned char \ [8].
Unsigned char newIP [4]={192168,0,111};
Int newCmdPort=3000;
Int newImgPort=4001;
\ [0]=newIP [0];
Temp [1]=newIP [1];
\ [2]=newIP [2];
\ [3]=newIP [3].
\ [4]=(char) (newCmdPort/256);
\ [5]=(char) (newCmdPort % 256);
\ [6]=(char) (newImgPort/256);
\ [7]=(char) (newImgPort % 256);
Const char * cIp=(const char *) temp (unsigned char *);
Sprintf (para. IpRemoteChange, cIp);
CodePudding user response:
Problem has changed, use the following code to achieve the parameter input dynamic link library, but a new problem, warned ipRemoteChange (char [] type) needs to be converted to char *, should how to convert? How the unsigned char conversion of a char *?Unsigned char \ [8].
Unsigned char newIP [4]={192168,0,111};
Int newCmdPort=3000;
Int newImgPort=4001;
\ [0]=newIP [0];
Temp [1]=newIP [1];
\ [2]=newIP [2];
\ [3]=newIP [3].
\ [4]=(char) (newCmdPort/256);
\ [5]=(char) (newCmdPort % 256);
\ [6]=(char) (newImgPort/256);
\ [7]=(char) (newImgPort % 256);
//const char * cIp=(const char *) (unsigned char *) temp;
//strcpy (para. IpRemoteChange, cIp);
//sprintf (para. IpRemoteChange, cIp);
for(int i=0; I<8; I++)
{
Para. IpRemoteChange [I]=\ [I];
}
CodePudding user response:
No translation, direct assignment will automatically convert,CodePudding user response:
Memcpy with more convenient, it is not recommended in this circulation assignment:
Memcpy (ipRemoteChange, temp, 8);
CodePudding user response:
Para. IpRemoteChange (pa) (char *)CodePudding user response:
Thank you for your reply, now the question is warned ipRemoteChange types defined as unsigned char [] [] when the input is correct, I need to send the UDP para. IpRemoteChange [], before using the sendto () method, can only send a const char *, so always want to para. IpRemoteChange [] into a const char *, probably because he is a byte (greater than 127), the result of the transformation is wrong, now I want to use UDP directly send byte [], should with what method?CodePudding user response:
Assignment do not use sprintf, sprintf is dealing with string, met 0 to truncate, char and unsigned char only need to pay attention to this problemCodePudding user response: