Thread: Printing only what is given

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Printing only what is given

    I have a program that is expected to compress an ASCII file by taking advantage of the fact that the MSB of each byte in a text file is 0, because ASCII codes go no higher than 127. I read in an ASCII file with fscanf(...), and store all of the characters in a character pointer. It then sends this char pointer to the compressBytes function, which does the necessary bit operations, and then sends back the appropriate char pointer representing what is to be printed. The new char pointer is printed to another file using the write(...) function. The problem is that in some special cases the character to be printed to the compressed file is ASCII 10, or line feed. When this character occurs, the write function prints two bytes at the same time: ASCII 13 followed by ASCII 10. How can i get my write(...) function to only print one byte, ASCII 10 in this case?

    Thanks for the help.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Open the file in binary mode instead of text mode.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    Thanks. It works as it should now. I wish I didn't spend five hours on that last night.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Printing Lines to .txt File
    By Programmer3922 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 12:45 PM
  3. generic printing preferences dialog box
    By stanlvw in forum Windows Programming
    Replies: 8
    Last Post: 06-27-2008, 02:20 AM
  4. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  5. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 04:46 AM