cobol and binary data written by C

M

Malcolm

can cobol read binary data written by fprintf (C function) ?
You're using fprintf() rather badly if you use it to write out binary data.
It is designed for text.
You'd have to ask in a COBOL group for an authorative answer, but I would be
extremely surprised if the language didn't have support for reading
arbitrary data files.
 
M

Mike

can cobol read binary data written by fprintf (C function) ?

I don't know about fprintf or C funtions but COBOL can read and
write binary data just fine. Care to explain a little better what
it is you're actually trying to do?
 
L

LX-i

Joe said:
I'm not up on what COBOL can do but, fprintf() writes text data, not
binary data.

COBOL can read and write both text and binary data - the key is, you've
got to know the structure of the file. You can have variable-length
records, so you could have one record with 10 characters, and another
with 20K.

I've never had experience interchanging data between the two languages,
so I can't tell you the best way to do that, or any problems that may arise.


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ (e-mail address removed) ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

LX-i wrote:
| Joe Wright wrote:
|
|> (e-mail address removed) wrote:
|>
|>> can cobol read binary data written by fprintf (C function) ?
|>
|>
|> I'm not up on what COBOL can do but, fprintf() writes text data, not
|> binary data.
|
|
| COBOL can read and write both text and binary data - the key is, you've
| got to know the structure of the file. You can have variable-length
| records, so you could have one record with 10 characters, and another
| with 20K.
|
| I've never had experience interchanging data between the two languages,
| so I can't tell you the best way to do that, or any problems that may
| arise.

I /have/ had experience exchanging data between COBOL and C programs, both
through file transfer and by program call.

In general, COBOL 'records' are equivalent to C 'structures', and with
recognition of the rules each language uses to format data, a program written
in one language can read data written by the other. Some things to watch for...

1) COBOL strings are implicitly length delimited. C strings are explicitly
delimited by the \0 character. C programs must know the implicit length of the
string variable and use memcpy() to extract or populate string data.

2) COBOL recognizes a variety of fixed-point formats, including COMP-3 (IBM
'packed' BCD format). C does not recognize this variety of formats, especially
COMP-3. Some caution (and programming) will be required to pass fixed point
values between the two languages.

3) COBOL recognizes an implicit decimal point in it's fixed-point formats. C
does not recognize any decimal point in it's equivalent integer formats. Some
caution (and programming) will be required to pass fixed point values between
the two languages.

4) COBOL records have different padding rules than C structures. A common
padding pragma will have to be found between the two.


- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAnsxDagVFX4UWr64RAmv3AJ40gp1cOfBnMSB/ZS6I/Wg6NldlMwCeJMRd
z/84sqQmiO/hrYHdIjD1PDQ=
=pvR1
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top