Skip to content

Instantly share code, notes, and snippets.

@mdippery
Created October 10, 2018 00:33
Show Gist options
  • Save mdippery/f6708a7497061453bfafd80882a6bbe9 to your computer and use it in GitHub Desktop.
Save mdippery/f6708a7497061453bfafd80882a6bbe9 to your computer and use it in GitHub Desktop.
Read one byte at a time and print the value
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 0;
int g = 0;
unsigned char ch;
if (argc > 1) {
g = atoi(argv[1]);
}
for (i = 0; i < g; i++) {
fread(&ch, 1, 1, stdin);
}
ch = 0;
fread(&ch, 1, 1, stdin);
printf("%#04x\n", ch);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment