Loop through hex variable in C
- by Jud Stephenson
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.