mkb@rover.ri.cmu.edu (Mike Blackwell) (02/21/91)
In MPW C++, the following code snippet compiles fine: #include <String.h> char foo[10]; strcpy(foo, "bar"); but if I replace "bar" with "\pbar", I get a bad argument error, stating that a const char * was expected, but it got an unsigned char [5] instead. Why is this? I know I can coerce it with a (char *)"\pbar", but that's ugly. What I really want is something like: Str255 foo; strcpy(foo, "\pbar"); but again, CFront doesn't like a Str255 in place of a char *. Why not? Is there a better way to achieve the same effect without type coercing both arguments? Thanks for any insight... Mike Blackwell mkb@rover.ri.cmu.edu
anders@verity.com (Anders Wallgren) (02/21/91)
strcpy works only on C strings. It will not work too well on P strings since it is expecting its string to be null-terminated. If you want to copy P strings, you either have to do it by hand, or, if you have access to MPW 3.2 betas, you can use PLstrcpy which is the P string equivalent of strcpy.
andrew@jhereg.osa.com (Andrew C. Esh) (02/22/91)
In article <12035@pt.cs.cmu.edu> mkb@rover.ri.cmu.edu (Mike Blackwell) writes: > >In MPW C++, the following code snippet compiles fine: > #include <String.h> > char foo[10]; > strcpy(foo, "bar"); >but if I replace "bar" with "\pbar", I get a bad argument error, stating >that a const char * was expected, but it got an unsigned char [5] instead. >Why is this? I know I can coerce it with a (char *)"\pbar", but that's ugly. > >What I really want is something like: Str255 foo; strcpy(foo, "\pbar"); but >again, CFront doesn't like a Str255 in place of a char *. Why not? Is there >a better way to achieve the same effect without type coercing both arguments? Yes, and if you had read the manual, you would have saved time. Page 170 of the MPW 3.0 C Reference manual has the section "Passing String Parameters", which describes the routines: char *p2cstr(StringPtr aStr); StringPtr c2pstr(char *aStr); which will do the job. They are declared in Strings.h and reside in the library CInterface.o. > >Thanks for any insight... Mike Blackwell > mkb@rover.ri.cmu.edu -- Andrew C. Esh andrew@osa.com (612)525-0000 Open Systems Architects, Inc. Minneapolis, MN 55416-1528 Does the universe really exist? Try starting from the opposite assumption and see where that gets you.