Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
int myfunction(char* error_string)
my $error = " "; mylib::myfunction($error); print $error;
This works as long as the string being returned is shorter than the number of spaces in the initialization of $error (10 spaces in this case), however any additional spaces in $error will still be printed after the error. For example, if the error returned is "Error 1", "Error 1 " will be printed with 3 spaces at the end. If the error returned is longer than 10 characters, the additional characters are truncated. I'm assuming this is becuase Perl counts the characters in a string instead of using null termination. Is there any way I can get Perl to "recount" the length of the string after returning from the function? I suppose I could search for the end of the string but it seems like there should be a better way to do this. Also, is there a better way to define the string I want to pass in to the function? The actual string needs to be 400 characters long and I'm not sure how to specify that I want a string with 400 characters. I suppose I could use a loop or the x operator to fill the string with spaces or some other character, but is there a better way to just allocate space for 400 characters?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing a string from C to Perl
by Zaxo (Archbishop) on Sep 07, 2001 at 04:14 UTC | |
|
Re: Passing a string from C to Perl
by stefp (Vicar) on Sep 07, 2001 at 04:32 UTC | |
|
Re: Passing a string from C to Perl
by John M. Dlugosz (Monsignor) on Sep 07, 2001 at 03:40 UTC | |
|
Re: Passing a string from C to Perl
by jlongino (Parson) on Sep 07, 2001 at 03:29 UTC | |
|
Re: Passing a string from C to Perl
by Anonymous Monk on Sep 07, 2001 at 20:02 UTC |