home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / vms / 19685 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.1 KB  |  46 lines

  1. Newsgroups: comp.os.vms
  2. 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
  3. From: winalski@adserv.enet.dec.com (Paul S. Winalski)
  4. Subject: Re: cdd and c
  5. Message-ID: <1992Dec22.004144.17281@nntpd2.cxo.dec.com>
  6. Lines: 33
  7. Sender: usenet@nntpd2.cxo.dec.com (USENET News System)
  8. Reply-To: winalski@adserv.enet.dec.com (Paul S. Winalski)
  9. Organization: Digital Equipment Corporation, Nashua NH
  10. References:  <9212212036.AA25675@top.magnus.acs.ohio-state.edu>
  11. Date: Tue, 22 Dec 1992 00:41:44 GMT
  12.  
  13.  
  14. In article <9212212036.AA25675@top.magnus.acs.ohio-state.edu>,
  15. Ung-Ho Yi <ungyi@magnus.acs.ohio-state.edu> writes:
  16. |>
  17. |>i am currently trying to include a string field from
  18. |>cdd to my c program.
  19. |>the string field in cdd was created for cobol, so when i tried to
  20. |>include the field to my c program, i am one character short.
  21.  
  22. You've run into a fundamental problem here with the ways that the two languages
  23. (COBOL and C) handle strings.  The string manipulation functions in C deal
  24. with NUL-terminated strings.  COBOL does not.  There are two ways that you
  25. can reconcile this difference:
  26.  
  27. 1) In your C program, process the string without requiring the NUL terminator.
  28.    This means avoiding functions such as strlen(), strcpy(), and the %s
  29.    formatting directive in printf(), all of which assume that a string is
  30.    NUL-terminated.
  31.  
  32. 2) Define the field in your CDD record to be one character bigger than it
  33.    has to be (this is the CDD equivalent of saying char x[7] when you want x
  34.    to hold a string with 6 characters in it).  Then just ignore the last
  35.    character position in your COBOL code.
  36.  
  37. It depends on your application which of these solutions is easier to implement.
  38. For example, if the field represents existing data in, say, disk file records,
  39. you have no choice--the format is dictated by the data on disk and your C code
  40. will just have to avoid using the functions that depend on a NUL terminator.
  41. On the other hand, if you are designing the whole application now, you can
  42. make the string field one bigger than it has to be, to accomodate C's NUL
  43. character.
  44.  
  45. --PSW
  46.