my C program prints out "HELLO--HELLO" with nothing in between

You seem to be implying that print extracted the first 6 characters and the last 6 characters of the string it was given. That's nonsense.

If the string passed to the parent process and therefore print contains nothing between the dashes, it's because $decoded_content is empty, which means the response's body was empty for that request.

You're going to insist the response wasn't empty, that it contained the UTF-16be document discussed elsewhere. And I agree. That means the test you said you ran is different than the one you said you ran. The problem is that you are treating the downloaded file as a NUL terminated string. That's a bug in your C program.

I don't get this if I print a regular string variable that I created, to file.

Good, that means there's nothing messing with your file handles. You are saving what you get.

With that I see it, except it obviously is encoded UTF16BE because of the "@^H@^e@^l@^l@^l@^o" characters I see.

I believe you mean UTF-16be. The case doesn't matter, but you missed the dash.

So the only problem is that you want to extract some data from the file you are downloading. For starters, we need to know in what format is the file you are downloading, and in what encoding do you want the extracted data to be.

Update: Updated response to first quote.


In reply to Re: Unexpected output from my PERL program. WHAT is my problem??? by ikegami
in thread Unexpected output from my PERL program. WHAT is my problem??? by URAvgDeveloper101

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.