Ovid has asked for the wisdom of the Perl Monks concerning the following question:
I'm playing around with Inline and I'm not getting the results that I expect. This snippet attempts to extract the date from a string and return it, but it's appending an 'x' to the end of the string. Any ideas why?
#!/usr/bin/perl -w use strict; use Inline C =><<'END_OF_C_CODE'; #include <string.h> void get_date( char* str ) { /* much thanks to wog and talexb for suggestions */ char date[9]; /* the date to return */ int index = 0; /* index of character in string */ Inline_Stack_Vars; Inline_Stack_Reset; while ( str[index++] != '|' ); strncpy( date, &str[index], 8); Inline_Stack_Push(newSVpvf(date)); Inline_Stack_Done; } END_OF_C_CODE print get_date("adb|20011225|asdf");
This prints "20011225x". Any ideas why?
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Inline::C not behaving as expected
by wog (Curate) on Dec 24, 2001 at 10:50 UTC |
Back to
Seekers of Perl Wisdom