PLEASE HELP - How to rename a block of binary bytes to a file

Discussion in 'C Programming' started by cpptutor2000@yahoo.com, Mar 11, 2008.

  1. Guest

    Could some C/Unix guru please help me with an odd problem I am
    having? I am using gcc on an embedded Linux device.

    I have a function return a block of bytes and I want to copy them into
    an empty file, all inside a function. For example, I would ideally
    like to have something like following:

    /*some function returns a pointer to a block of unsigned chars - this
    part works fine
    */
    sprintf(pBuff, "fopen file_name \"%s\"\n", "wb");
    Now the question is how do I copy the block of bytes
    obtained just above, to the file I have just opened?

    Any hints or suggestion would be greatly appreciated - thank you in
    advance for your help.
     
    , Mar 11, 2008
    #1
    1. Advertising

  2. Richard Bos Guest

    "" <> wrote:

    > sprintf(pBuff, "fopen file_name \"%s\"\n", "wb");


    I advise you to
    - seriously rethink that line;
    - _not_ crosspost needlessly (f'ups set);
    - ponder on the existence of fread().

    Richard
     
    Richard Bos, Mar 11, 2008
    #2
    1. Advertising

  3. santosh Guest

    wrote:

    > Could some C/Unix guru please help me with an odd problem I am
    > having? I am using gcc on an embedded Linux device.
    >
    > I have a function return a block of bytes and I want to copy them into
    > an empty file, all inside a function. For example, I would ideally
    > like to have something like following:
    >
    > /*some function returns a pointer to a block of unsigned chars - this
    > part works fine
    > */
    > sprintf(pBuff, "fopen file_name \"%s\"\n", "wb");


    This is wrong.

    > Now the question is how do I copy the block of bytes
    > obtained just above, to the file I have just opened?


    Open your file with fopen and write to it with fwrite and close with
    fclose. Why shouldn't this method work for you?

    <snip>
     
    santosh, Mar 11, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. morrell
    Replies:
    1
    Views:
    977
    roy axenov
    Oct 10, 2006
  2. Yandos
    Replies:
    12
    Views:
    5,137
    Pete Becker
    Sep 15, 2005
  3. scad
    Replies:
    4
    Views:
    966
    James Kanze
    May 28, 2009
  4. Guest
    Replies:
    6
    Views:
    1,728
    Guest
    Apr 25, 2010
  5. carrzkiss
    Replies:
    0
    Views:
    454
    carrzkiss
    Jan 15, 2009
Loading...

Share This Page