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