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?
In reply to Passing a string from C to Perl by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |