home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 20059 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.9 KB  |  59 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!bgsuvax!m64-134.bgsu.edu!user
  3. From: dnebing@andy.bgsu.edu (Dave Nebinger)
  4. Subject: Re: Please help me pull this string
  5. Message-ID: <dnebing-181292162419@m64-134.bgsu.edu>
  6. Followup-To: comp.sys.mac.programmer
  7. Sender: usenet@andy.bgsu.edu (USENET)
  8. Organization: Bowling Green State University B.G., Oh.
  9. References: <q8m2+qj@rpi.edu>
  10. Date: Fri, 18 Dec 1992 21:31:08 GMT
  11. Lines: 46
  12.  
  13. In article <q8m2+qj@rpi.edu>, abduls@aix.rpi.edu (Saiful Azuan Abdul Aziz)
  14. wrote:
  15. > My template looks like this (in ResEdit)
  16. >     LABEL        FIELD TYPE
  17. >     # of Data        ZCNT
  18. >     ****        LSTC
  19. >     Starting Pts    DLNG
  20. >     Ending Pts    DLNG
  21. >     Line Name        PSTR
  22. >     ****        LSTE
  23. >     
  24. > When I translated this to my C data structure, I make it somthing like
  25. > this
  26. > struct    MyData{
  27. >     long    StartPt;
  28. >     long    EndPt;
  29. >     Str255    LineName;
  30. > };
  31. > My problem is that I can't get the pascal string working when I did the
  32. > BlockMove. The pascal string is not in constant size. It is stored in N+1 byte
  33. > style. (N is # of character). Below is the code that I did to get my
  34. > resource (part of it)
  35.  
  36.   Str255 and the PSTR are two different things.  Str255 variables take
  37. up 256 bytes of memory.  The first is the length, then the string, followed
  38. by the remaining bytes.
  39.  
  40.   If a Str255 is initialized to "\pabcdefghijklmnopqrstuvwxyz", the length
  41. byte will be 26, but the 256 bytes of memory reserved for the variable are
  42. still there, just ignored.  If you reset the variable to "\p12345", the
  43. length byte will be 5, but in memory it will look like "\p12345fghi...".
  44.  
  45.   Your 2 choices to handle this is to initialize your resource to contain
  46. Str255 strings (save all 256 bytes) or manually get and put the size of
  47. the string you want.  The advantage to the first method is that it is alot
  48. easier to write, but your template will not look as pretty.
  49.  
  50.   Hope this helps,
  51.  
  52.   David Nebinger
  53.   dnebing@andy.bgsu.edu
  54.