I have a very simple following code which gets 4 bytes from stdin
and prints them out byte by byte in hex format.
// Code may be different but the point is to input any byte value 0 to 255 from stdin
int main(int argc, char** argv) {
char buffer[4];
read(0, buffer, 4); // or gets(buffer)
int i;
for(i = 0; i < 4; i++) {
printf("%x", buffer[i]);
}
}
The problem I am encountering is that I am limited by what I can type through keyboard so I cannot supply any byte to stdin
. For example, if I am dealing with ACSII, it is not possible to give 0x11
because ASCII 0x11
is Device Control 1 (oft. XON)
which keyboard does not have. I have more problem if I am dealing with UTF-8 because characters does not use full range of byte (it goes up to 0x7f and start to use 2 bytes).
I am looking for something like "\x11\x11\x11\x11"
in C style string or constant format like 0x11111111
in C.
What ways are there to give any byte 0-255 to stdin so that I have full control on what value goes to the buffer?
EDIT : I am on a system where I do not have a privilege to create a file.
Sadly, I've been stuck on this for a week now. Thank you very much!.