appending space in binary data in c

Hi ...

I am having a string in the buffer .. It is binary data it may contain space . When i try to append a space in using strcpy it is taking the inbetween \\n as the end and appending space .. 

How to append space in the binary data in C ?? please let me know

Thanks in advance,
Arun.

Since it is binary data, it may contain "characters" that have any ascii value (including, possibly, 0). Don't use the strxxx functions as they use these as delimiters. You could look at the memcpy family instead.

Presumably you have a buffer filled with data and you know the length. Given those two bits of information, you simply set the "length" byte to space and increment length. For example:

#include <stdio.h>

int main ( void )
{
    char        Buffer [1024] = "ABC\0DEF\n";
    int         Length = 8;

    Buffer [Length++] = ' ';

    fwrite (Buffer, 1, Length, stdout);
/*  or
     write (1, Buffer, Length);
*/

}

For the same reason you can not use strcat, you can not use the standard printf(3C) functions with a "%s" tag. It would stop at the NUL byte '\0' which is at the 4th byte (or offset 3).

I hope this helps.