The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pax error on appending data to LTO3 kwliew999 AIX 0 04-20-2008 08:01 PM
appending space to variable viv1 Shell Programming and Scripting 5 02-04-2008 04:01 AM
Appending data into a variable michaeltravisuk Shell Programming and Scripting 4 03-08-2007 08:45 PM
Convert Binary data to ascii data krishna UNIX for Advanced & Expert Users 4 11-05-2004 01:12 PM
help on appending data to existing data precious51980 UNIX for Dummies Questions & Answers 1 01-27-2001 09:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-12-2007
Registered User
 

Join Date: Oct 2004
Posts: 235
Thumbs up 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.
Reply With Quote
Forum Sponsor
  #2  
Old 02-12-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
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.
Reply With Quote
  #3  
Old 02-12-2007
Registered User
 

Join Date: Feb 2006
Location: Schenectady, NY
Posts: 130
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:


Code:
#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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0