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

  • SEARCH
  • Home
  • 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 8421365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:07:57+00:00 2026-06-10T03:07:57+00:00

I use this routine to do a binary read from file to memory, which

  • 0

I use this routine to do a binary read from file to memory, which worked fine until now… on iOS at least, in the simulator(…don’t have the paid developer program(yet 😉 ))

The numbers e.g. fileSize, bytesRead are OK, but it gives gibberish at the end…

I can’t have overwritten memory, since I do the output right away…

Then I thought it could be an alignment boundary issue e.g. fileSize % 4 = det. gibberish.
But that would be strange behavior, the function gets a size and a count, the lib should calc a multiple byte read on the background, so that shouldn’t cause the problem…

Here’s the code I use:

uint8_t *readFileToMemory(FILE *fp)
{
    fseek(fp, 0, SEEK_END);
    long fileSize = ftell(fp);
    rewind(fp);
    //
    printf("fileSize %lu bytes\n",fileSize);
    //
    uint8_t *fileData = NULL;
    //
    fileData = (uint8_t *)requestMemory(fileData, (MEM_TYPE_MEMSIZE)fileSize, BF_MEM_ZERO_NO, "readFileToMemory()");
    fread(fileData, 1, (size_t)fileSize, fp);
    //
    long sizeRead = fread(fileData, 1, (size_t)fileSize, fp);
    printf("sizeRead %lu bytes\n",sizeRead);
    //
    fclose(fp);
    //
    printf("+\n+\nfileData:\n%s+\n+\n",fileData);
    //
    return fileData;
}

The reason why I post this question is “WHY the gibberish?” on iOS-sim, I do have a simple workaround btw…

Niels

  • 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-10T03:07:59+00:00Added an answer on June 10, 2026 at 3:07 am

    I am here now, so I might as well provide an answer for closure 😉

    I forgot to put an ‘\0’ at the end of the binary file before passing it along as (c/glsl NULL-terminated)string… Oops 🙂

    I thank borrrden for his remarks on the Apple libs binary-read, which I still need to look into… (time time time)

    Niels

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ArrayList of Routine objects and I must use this method to
All, I've a javascript routine which returns a string value, I want to use
I've notice that StackOverflow use this url: http://stackoverflow.com/posts/123123/revisions How can I add such routing
In ASP.NET MVC (default routing),I'd like to use a URL like this to return
use this website a lot but first time posting. My program creates a number
I use this function for transforming URLs to images on output. function InsertLink(T){ var
i use this line of code : [self parseXMLFileAtURL:url]; And i get this error
I use this script in two different servers: function curlGetFileInfo($url, $cookies=default){ global $_config; $ch
I use this code : MethodInvoker TileLoadCompleteMethodInvoker = delegate() { CleanStatusLabelTimer.Enabled = true; MemoryTextBox.Text
i use this script to load content of some div, inside another div: $(function()

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.