home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / vms / 18274 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  2.5 KB

  1. Xref: sparky comp.os.vms:18274 comp.lang.c:16913
  2. Newsgroups: comp.os.vms,comp.lang.c
  3. Path: sparky!uunet!usc!sdd.hp.com!ux1.cso.uiuc.edu!jsivier
  4. From: jsivier@ux1.cso.uiuc.edu (Jonathon Sivier )
  5. Subject: String Pointer Passing Problem with VAX C
  6. Message-ID: <By1Dvp.Gpu@ux1.cso.uiuc.edu>
  7. Organization: University of Illinois at Urbana
  8. Date: Fri, 20 Nov 1992 22:45:10 GMT
  9. Lines: 38
  10.  
  11.     I have run into a very wierd bug/problem.  I have a series of routines
  12. that I am passing string (char) pointers between.  In the top level I declare
  13. some automatic char arrays of a given size.  I then pass the pointers to these
  14. arrays to other routines for the return of a char string.  In the routine
  15. which is called I create the string using sprintf and place it into a local
  16. string variable.  Before returning from the routine I copy the local string
  17. into the argument string which was passed (I've tried both strcpy and sprintf,
  18. the results are the same).  Upon return to the calling routine I find that the
  19. string consists of a large number of spaces (the same number as the size of
  20. the array) and then the string.  If the string is being returned from more
  21. than one level down in the heirarchy of the program, the string will be padded
  22. with that many times the number of spaces and then the actual string.
  23.  
  24.    If, before calling the first routine in the chain, I initialize the first
  25. array with a constant string everything seems to work.  Does this mean you
  26. can't pass pointers to automatically created arrays?  Do only externally
  27. declared arays of chars work when being passed between routines?  Why can't
  28. a routine which is passed the pointer to an automatically declared array from
  29. another routine write values into that array?
  30.  
  31.    If anyone has any ideas I'd like to hear them.  Otherwise I'll have to
  32. make all my char arrays global and that will make recursion difficult, to
  33. say the least.
  34.  
  35. Thanks for your assistance.
  36.  
  37. Jonathan
  38.  
  39. -------------------------------------------------------------------
  40. |  Jonathan Sivier               |  Ballo ergo sum.               |
  41. |  jsivier@ux1.cso.uiuc.edu      |  (I dance therefore I am.)     |
  42. |  Flight Simulation Lab         |            - des Cartwright  |
  43. |  Beckman Institute             |                                |
  44. |  405 N. Mathews                |                                |
  45. |  Urbana, IL  61801             |                                |
  46. |  Work: 217/244-1923            |                                |
  47. |  Home: 217/359-8225            |                                |
  48. -------------------------------------------------------------------
  49.