Thread: ASCII Display

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    5

    ASCII Display

    Hi have got to write a program to display a text file within UNIX very much the same as the cat function.
    One of the problems is to display the ASCII control characters that's is the the text printable form for example tab represented as \t.
    I have managed to just print it out without the control characters but am lost for ideas for how to attack this bit.

    Any ideas PLEASE!

    Mark

  2. #2
    Registered User vinit's Avatar
    Join Date
    Apr 2006
    Location
    India
    Posts
    39
    if u encounter /t then print it as printf("\t"); it will do fine.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    5
    i need it to dispaly the ASCII control characters. Where at the moment i have:

    ch = fgetc(in_file);
    if (ch != EOF)
    putchar(ch);


    where ch is an int, and in_file is a FILE.
    Displays the text as it is to be shown not the control characters.

  4. #4
    Registered User wintellect's Avatar
    Join Date
    Mar 2006
    Posts
    24
    You could use a switch() statement to check the contents of ch, and if it's below a certain ASCII character value print something else instead

  5. #5
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by vinit
    if u encounter /t then print it as printf("\t"); it will do fine.
    That will print a tab. You want printf("\\t"); to display \t

  6. #6
    Registered User
    Join Date
    Feb 2006
    Location
    Great India
    Posts
    24
    Quote Originally Posted by campebell2004
    i need it to dispaly the ASCII control characters. Where at the moment i have:

    ch = fgetc(in_file);
    if (ch != EOF)
    putchar(ch);


    where ch is an int, and in_file is a FILE.
    Displays the text as it is to be shown not the control characters.
    Don't you think that ch should be a charecter type for accessing the text.

    One more thing i wanna add INSTEAD of using "if" use "while" because i don't think that above mentioned loop will work more than once or Use the "CONTINUE" with "if"



    REALNAPSTER

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No. It should be an int, because EOF won't work correctly if you try to smash it into a char.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM