Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 19
Registered: ‎01-21-2012
My Device: PlayBook
My Carrier: none
Accepted Solution

reading a file from app/native with fopen() and fgetc()

 

Figured out that if I put a data file in my main folder (the same one where LICENSE and NOTICE are stored) and when I then add that file as an asset in bar-description.xml, I can open it.

 

At least in the debugger, FILE * fp = fopen("app/native/file.dat", "r"); returns what looks to be a filehandle, it's not 0x0 or -1. However when I then start reading data using int c = fgetc(fp); I do get data, but not from my file. It seems to be fully random bytes.

 

Isn't it funny that what was always supposed to be the easy stuff, is sometimes the hardest nut to crack? I built a work around, which worked fine on the emulator, but then failed to build as ARM code for the device. It made that I'm now too late for the free PlayBook. :-(

 

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: reading a file from app/native with fopen() and fgetc()

first of all you are not too late -) but should hurry up...

Please paste your code snippet that does not work as expected.

Developer
Posts: 19
Registered: ‎01-21-2012
My Device: PlayBook
My Carrier: none

Re: reading a file from app/native with fopen() and fgetc()

Yes, I just saw that note about the extended deadline too !! :-) It's now March 2nd, plenty of time for me....

 

Now, thanks a lot for asking me to add the code snippet, because while cut-and-pasting it, I suddenly noticed the error I had made. My asset line in bar-descriptor.xml looked like:

 

    <asset path="world.png">world.ppm</asset>

which contains a typo, or better said a correction only partly executed. I changed 'png' to 'ppm' but I forgot to do it everywhere (2x in the xml file, 1x in the source code).

 

Happy coding again.....

 

Developer
Posts: 19
Registered: ‎01-21-2012
My Device: PlayBook
My Carrier: none

Re: reading a file from app/native with fopen() and fgetc()

 

and for those who don't know how this works (we were all newbies at one time)


    FILE *file;
    BYTE *data;
    BYTE *p;
    BYTE c = '\0';
    int width = 720;
    int height = 360;
    int i;

    file = fopen ("app/native/world.ppm", "rb");
    data = malloc (width * height * 3);

    // skip header
    while (c != '\n');
        c = fgetc (file);
    }
    // read data
    p = data;
    for (i = 0; i < (width * height * 3); i++) {
        *p++ = (BYTE) fgetc (file);
    }
    // or instead:  fread (data, width * height * 3, 1, file);

    fclose (file);


Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: reading a file from app/native with fopen() and fgetc()

So, solved?

Developer
Posts: 19
Registered: ‎01-21-2012
My Device: PlayBook
My Carrier: none

Re: reading a file from app/native with fopen() and fgetc()

Yes...