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.


In reply to Inline::C not behaving as expected by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.