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

This is a discussion on PLEASE HELP - How to rename a block of binary bytes to a file - Unix ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

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

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

    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.

  2. Re: PLEASE HELP - How to rename a block of binary bytes to a file

    "cpptutor2000@yahoo.com" 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

  3. Re: PLEASE HELP - How to rename a block of binary bytes to a file

    cpptutor2000@yahoo.com 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?




+ Reply to Thread