LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-02-2006, 07:09 PM   #1
smoothdogg00
Member
 
Registered: Feb 2006
Location: Maine
Distribution: Ubuntu
Posts: 44

Rep: Reputation: 15
Question 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:

Code:
  int c;

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

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

  fclose(Fp);
The two program results are as follows:
Quote:
[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
0000014
"%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.

Last edited by smoothdogg00; 03-02-2006 at 10:00 PM.
 
Old 03-02-2006, 10:44 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Code:
od -b test
and
Code:
man od
will help you understanding what's going on.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python: converting a 3 character octal string into and ASCII char llama_meme Programming 1 07-06-2010 02:00 PM
ncurses printing character array prob. slzckboy Programming 3 07-31-2005 08:51 AM
Problem with reading and printing a character hubabuba Programming 3 02-28-2005 02:41 PM
Textual representation of numbers lackluster Programming 4 09-05-2004 04:02 PM
Can 't convert from a character to octal value in memory Linh Programming 2 07-21-2003 03:11 PM


All times are GMT -5. The time now is 06:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration