ushtabalakh
Programmer
- Jun 4, 2007
- 132
Hi there,
I've written the following code to print contents of a file,
I use it in command line like this.
toHex < sample.txt
it works for text files but not for binary files, I have to get the binary file as input stream; any ideas on how this could be possible? I'm looking for a getchar like function that would get binary characters too.
while((c=getchar()) != EOF && lines <= 1000) {
// Display 16 bytes per line
if (limit % 16 == 0)
{
if (limit!=0) //Printing a crlf after each 16 bytes except the first line
printf("\n");
//Printing a 4 digit line number in hex format
printf("%.4X: ",limit);
}
//Print the given character
printf("%.2X ", (int)c);
limit++;
}
I've written the following code to print contents of a file,
I use it in command line like this.
toHex < sample.txt
it works for text files but not for binary files, I have to get the binary file as input stream; any ideas on how this could be possible? I'm looking for a getchar like function that would get binary characters too.
while((c=getchar()) != EOF && lines <= 1000) {
// Display 16 bytes per line
if (limit % 16 == 0)
{
if (limit!=0) //Printing a crlf after each 16 bytes except the first line
printf("\n");
//Printing a 4 digit line number in hex format
printf("%.4X: ",limit);
}
//Print the given character
printf("%.2X ", (int)c);
limit++;
}