By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,276 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,276 IT Pros & Developers. It's quick & easy.

cobol and binary data written by C

P: n/a
can cobol read binary data written by fprintf (C function) ?
Nov 14 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"hp******@yahoo.com" <eh***********@yahoo.com> wrote

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.
Nov 14 '05 #2

P: n/a
hp******@yahoo.com 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.

--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #3

P: n/a
> 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?
Nov 14 '05 #4

P: n/a
Joe Wright wrote:
hp******@yahoo.com 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.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LX*****@Netscape.net ~
~ _____ / \ | ~ 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 ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~

Nov 14 '05 #5

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

LX-i wrote:
| Joe Wright wrote:
|
|> hp******@yahoo.com 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-----
Nov 14 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.