home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.vms
- Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!engage.pko.dec.com!nntpd.lkg.dec.com!nntpd2.cxo.dec.com!adserv.enet.dec.com!winalski
- From: winalski@adserv.enet.dec.com (Paul S. Winalski)
- Subject: Re: cdd and c
- Message-ID: <1992Dec22.004144.17281@nntpd2.cxo.dec.com>
- Lines: 33
- Sender: usenet@nntpd2.cxo.dec.com (USENET News System)
- Reply-To: winalski@adserv.enet.dec.com (Paul S. Winalski)
- Organization: Digital Equipment Corporation, Nashua NH
- References: <9212212036.AA25675@top.magnus.acs.ohio-state.edu>
- Date: Tue, 22 Dec 1992 00:41:44 GMT
-
-
- In article <9212212036.AA25675@top.magnus.acs.ohio-state.edu>,
- Ung-Ho Yi <ungyi@magnus.acs.ohio-state.edu> writes:
- |>
- |>i am currently trying to include a string field from
- |>cdd to my c program.
- |>the string field in cdd was created for cobol, so when i tried to
- |>include the field to my c program, i am one character short.
-
- You've run into a fundamental problem here with the ways that the two languages
- (COBOL and C) handle strings. The string manipulation functions in C deal
- with NUL-terminated strings. COBOL does not. There are two ways that you
- can reconcile this difference:
-
- 1) In your C program, process the string without requiring the NUL terminator.
- This means avoiding functions such as strlen(), strcpy(), and the %s
- formatting directive in printf(), all of which assume that a string is
- NUL-terminated.
-
- 2) Define the field in your CDD record to be one character bigger than it
- has to be (this is the CDD equivalent of saying char x[7] when you want x
- to hold a string with 6 characters in it). Then just ignore the last
- character position in your COBOL code.
-
- It depends on your application which of these solutions is easier to implement.
- For example, if the field represents existing data in, say, disk file records,
- you have no choice--the format is dictated by the data on disk and your C code
- will just have to avoid using the functions that depend on a NUL terminator.
- On the other hand, if you are designing the whole application now, you can
- make the string field one bigger than it has to be, to accomodate C's NUL
- character.
-
- --PSW
-