Loop through hex variable in C

Posted by Jud Stephenson on Stack Overflow See other posts from Stack Overflow or by Jud Stephenson
Published on 2010-05-17T20:06:02Z Indexed on 2010/05/17 20:10 UTC
Read the original article Hit count: 299

Filed under:
|
|

I have the following code in a project that write's the ascii representation of packet to a unix tty:

int written = 0; 
int start_of_data = 3; 
//write data to fifo 
while (length) { 
        if ((written = write(fifo_fd, &packet[start_of_data], length)) == -1) 
{ 
                printf("Error writing to FIFO\n"); 
        } else { 
                length -= written; 
        } 
} 

I just want to take the data that would have been written to the socket and put it in a variable. to debug, I have just been trying to printf the first letter/digit. I have tried numerous ways to get it to print out, but I keep getting hex forms (I think).

The expected output is: 13176 and the hex value is: 31 33 31 37 36 0D 0A (if that is even hex)

Obviously my C skills are not the sharpest tools in the shed. Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++