Writing chars to a stream w/o being Translated? 
Author Message
 Writing chars to a stream w/o being Translated?

        I am writing a program for a debit card system in which the two systems involved commincate via a modem.  I am using a file pointer to send and receive messages on the stream.  The program as a whole is running great, but there is
one bug that is wreaking havoc on the system.  The bug causes the whole debit
card system to fail and then have to be reloaded.

        The problem is as follows:
        The message that is sent is has an LRC character calculated for it, and it is sent on the end of the message to allow the recieving end to check the
validity of the message.  The problem comes when the LRC is calculated to be a
a horizontal tab (HT - hex 09) character.  Instead of putting the character
itself on the stream UNIX is interpreting it as a tab and putting 2-5 spaces
on the stream.

        I have used fprintf, fwrite, fputc,and fputs (putting the LRC in an
array of two characters) each time I get the same result.  Other characters
such as line feeds, CRs, and other control characters work just fine and don't
get translated.

        Does anyone know of a way to send a character out on a stream (using a
file pointer) that will make it so the character is not translated when it is
put on the stream (besides the afore mentioned ways)?  I might be wrong and it
might be a UNIX problem but any help would be appreciated.

                Thanks in advance for any help

                Austin Adamson
                Systems Adminstrator / Programmer
                BYU bookstore.



Tue, 20 May 1997 04:23:37 GMT  
 Writing chars to a stream w/o being Translated?
|>
<snip>
|> a horizontal tab (HT - hex 09) character.  Instead of putting the character
|> itself on the stream UNIX is interpreting it as a tab and putting 2-5 spaces
|> on the stream.

Have you tried opening the stream in binary mode ("wb")? Unfortunately, my
compiler does not do this, so I have no way of checking this.

Cheers
Tanmoy
--

Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87544-0285,USA H:#3,802,9 St,NM87545

<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]



Tue, 20 May 1997 04:45:33 GMT  
 Writing chars to a stream w/o being Translated?

Quote:
>    The message that is sent is has an LRC character calculated for it,
> and it is sent on the end of the message to allow the recieving end to
> check the a
> validity of the message.  The problem comes when the LRC is calculated to be a
> a horizontal tab (HT - hex 09) character.  Instead of putting the character
> itself on the stream UNIX is interpreting it as a tab and putting 2-5 spaces
> on the stream.

    Are you writing both ends of this transfer? If so, then you have
    at least two options...

    o   Change the transfer so that all special characters are escaped
        somehow. For example, when the sender wants to write an 09, it
        could send something like "\09", and when it wants to send a \
        it could send a "\5C". Then the receiver can filter these
        codes at its end, converting them back.

    o   Find out how to disable translation on the Unix devices you
        are using to write and read. It sounds more like translation
        at the receiver than at the sender, but it may be worth
        checking the documentation for ioctl() and related functions
        at both ends.

Quote:
>    Does anyone know of a way to send a character out on a stream (using a
> file pointer) that will make it so the character is not translated when it is

    Well, the normal method is just to open the file with "wb" and
    "rb". When that doesn't work, then you are looking at a system-
    specific problem.

Quote:
>            Austin Adamson

--

***             Count Templar, ELITE, Cobra Mk III (FM-287)             ***


Wed, 21 May 1997 11:31:11 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. translating virtual keys to char

2. Create a stream from an umanged char array

3. stream to char* conversion

4. unsigned char and file streams

5. replace char array in string or streams.

6. AVI Streams Read/Write

7. How to write a C++ stream to a C FILE

8. Network Stream Read/Write Problem

9. Writing an array of floats to a stream

10. Write struct to a stream?

11. write()'s to network stream are sent but not received

12. How to write in color with output stream (cout)

 

 
Powered by phpBB® Forum Software