Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:10:36+00:00 2026-06-05T17:10:36+00:00

This is the ‘C++’ Structure used. struct gross { char date[11]; char ac[128]; char

  • 0

This is the ‘C++’ Structure used.

struct gross
    {
        char date[11];
        char ac[128];
        char type[5];
        float mvalue;
        float netraw;
        float netfer;
        char stat[128];
        float firr;
        float acb;
    };

This is the content of binary file generated when compiled with GCC compiler.

12/12/1995 d us 12.23 34.12 90.12 fees 12 56.12
01/01/1998 a us 52.23 54.12 10.12 fees 92 16.12
31/12/1999 a us 52.23 54.12 10.12 fees 92 16.12
31/12/1999 d us 12.23 34.12 90.12 fees 12 56.12
01/01/2000 a us 52.23 54.12 10.12 fees 92 16.12
01/01/2000 z us 12.23 34.12 90.12 fees 12 56.12
31/12/2010 a us 52.23 54.12 10.12 fees 92 16.12
31/12/2010 d us 12.23 34.12 90.12 fees 12 56.12

The PHP coding to read the content of the above binary file.

echo "<table>";
while (!feof($f)) {

  if ($s = fread($f, 292)) {

        $nn = unpack('a11date/a128ac/a5type/fmvalue/fnetraw/fnetfer/a128stat/ffirr/facb', $s);

        echo "<td>" . $nn[date] ."</td>";
        echo "<td>" . $nn[ac] . "</td>";
        echo "<td>" . $nn[type] . "</td>";
        echo "<td>" . $nn[mvalue] . "</td>";
        echo "<td>" . $nn[netraw] . "</td>";
        echo "<td>" . $nn[netfer] . "</td>";
        echo "<td>" . $nn[stat] . "</td>";
        echo "<td>" . $nn[firr] . "</td>";
        echo "<td>" . $nn[acb] . "</td>";
        echo "</tr>";
 }
}
        echo "</table>";
fclose($f);
?>

This is what I got from the above code. What I’m getting is lot of garbage values in the second and seventh field. And the precision exceeds for the float fields. How to fix this?

12/12/1995 d¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885

01/01/1998 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233

31/12/1999 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233

31/12/1999 d¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885

01/01/2000 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233

01/01/2000 z¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885

31/12/2010 a¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 52.229999542236 54.119998931885 10.119999885559 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 92 16.120000839233

31/12/2010 d¸³M·g·ew·¤dw·àew·Öúr·ÿÿÿÿ,w·ø;w·Ìª¹¿ô{·{·‹ây·Ð{·SpP·ip·¤dw·ew·€5w·ôOg·
X«¹¿»qP·äSg us 12.229999542236 34.119998931885 90.120002746582 fees·5rP· #Ä äSg· rP·ô›Å #Ä 5rP·0#o·¸xw·x«¹¿·ÅÿÿýŽäSg·¸xw·ÆD¬¹¿L¬¹¿5rP·pòy· 12 56.119998931885

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:10:37+00:00Added an answer on June 5, 2026 at 5:10 pm

    In PHP’s pack and unpack, the formatting code a stands for NUL padded string. In this case it looks like the second and seventh field are not NUL padded; they just have NUL to indicate where the string ends, followed by random data.

    To get the part of the string before NUL you can use substr and strpos:

    $input = "a\000b"; // string with embedded NUL 
    $output = substr($input, 0, strpos($input, "\000"));
    var_dump($output); // string(1) "a"
    

    The float fields have their correct values, the values you see in the output from the C program are rounded. To do the same in PHP you could use sprintf for example:

    $input = 16.120000839233;
    $output = sprintf("%.2f", $input);
    var_dump($output); // string(5) "16.12"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code: $.ajax({ url: someUrl, type: PUT, data: { id: id, message:
This url structure is proposed for SEO optimization. So suggesting another structure will not
this gives me an error, Bad Reciever type 'NSIntegar (aka 'int'). NSString *tempTag =
this is what i have so far: type u = {str : string} //some
This does not work: CCSprite *testscale=[CCSprite spriteWithSpriteFrame:starFrame]; testscale.scale=0.5; float starWidth=testscale.contentSizeInPixels.width; CCLOG(@contentpixels: %f contentsize: %f,starWidth,
This is really just for my own use: I would like to be able
This somehow simple task is not so simple. I can get the number of
This has been a rather problematic issue on numerous occasions. We have alot of
This should be simple, but the answer is eluding me. If I've got a
this is my code that I write it but I want to use LINQ

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.