-   Programming (
-   -   Printing the octal representation of a character. (

smoothdogg00 03-02-2006 08:09 PM

Printing the octal representation of a character in C...
First let me start by saying I am new to C. My program needs to read in a character in binary(including non-printable characters) and then display the character in octal representation, like the 'od' program does. My code is as follows:


  int c;

  FILE *Fp;
  Fp = fopen(argv[1], "rb");

  while((c = fgetc(Fp)) != EOF)
      fprintf(stdout, "%06ho\t", c);


The two program results are as follows:

[solaris]$ myod test
000150 000145 000154 000154 000157 000040 000167 000157 000162 000154 000144 000012

[solaris]$ od test
0000000 064145 066154 067440 073557 071154 062012
"%06ho" was given to me for formatting purposes, so I know that is correct.

I'll admit, I don't really understand...basically typing "myod test" should perform the same function as typing "od test", where test is a binary file.

Thanks for your help.

jlliagre 03-02-2006 11:44 PM


od -b test

man od
will help you understanding what's going on.

All times are GMT -5. The time now is 04:27 PM.