i use sscanf in this code
while(totalByte < sizeof(rdata))
{
read(client_sockfd, &buffer[totalByte],1);
printf("bytes[%d] : %x \n", totalByte, buffer[++totalByte]);
}
use this code and i got a result like this
client send 1 1 +
bytes[0] : 0
bytes[1] : 0
bytes[2] : 0
bytes[3] : 1
bytes[4] : 0
bytes[5] : 0
bytes[6] : 0
bytes[7] : 1
bytes[8] : 2b
bytes[9] : 0
bytes[10] : 0
bytes[11] : 0
bytes[12] : 0
bytes[13] : 0
bytes[14] : 0
bytes[15] : 0
bytes[16] : 0
bytes[17] : 0
bytes[18] : 0
bytes[19] : 0
got a result
then i use sscanf method
sscanf(buffer,"%d%d%c" ,&rdata.left_num, &rdata.right_num, rdata.op);
printf("%d %c %d \n", ntohl(rdata.left_num),rdata.op,ntohl(rdata.right_num));
but when print rdata(structure)'s value , get a 0 value(init value).
0 0
i know sscanf method split a string and insert a value
Is there a any misunderstood for me?
this is what i used structure
struct cal_data
{
int left_num;
int right_num;
char op;
int result;
int error;
};