appending space in binary data in c


 
Thread Tools Search this Thread
Top Forums Programming appending space in binary data in c
# 1  
Old 02-12-2007
MySQL 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.
# 2  
Old 02-12-2007
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.
# 3  
Old 02-12-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with data appending to a file

Hi I have a file called text.txt contains x y z when i run a command i will get output like below x 20 z 30 i want to insert x, z value in text.txt file and should be like this x 20 y 0 z 30 can anyone help me please? (1 Reply)
Discussion started by: siva kumar
1 Replies

2. Shell Programming and Scripting

Appending timestamp to a file. Why do I need this space ?

Version Info $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) $ $ echo $0 -ksh I was trying to append date to the file name. The following syntax has worked $ touch HELLO-`date '+%d-%b-%Y'`.txt $ ls -alrt HELL* -rw-r--r-- 1 rlapp oinstall 0 Feb 20... (2 Replies)
Discussion started by: John K
2 Replies

3. Shell Programming and Scripting

appending previous data.

I have on file abc.txt abc.txt: 20090807 Now I want to delete empty lines which has tap/whit spaces from abc.txt .and store the date value in the file into variable.some processs will update the this file with some date . if the process updtes thiis file with empty string , write the... (3 Replies)
Discussion started by: Gopal_Engg
3 Replies

4. Shell Programming and Scripting

Blank Space is not appending in each row of CSV File - Shell Script

I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces. In my SQL script,the last column is like below. RPAD(' ',23,' ') -- Padding 23 blank Spaces The CSV file is generated but the sapce(23 spaces) is... (2 Replies)
Discussion started by: praka
2 Replies

5. Shell Programming and Scripting

Appending data into a variable

Hi, I would like to know if it's possible to append data into a variable, rather than into a file. Although I can write information into a temporary file in /tmp, I'd rather if possible write into a variable, as I don't like the idea that should my script fail, I'll be polluting the server with... (5 Replies)
Discussion started by: michaeltravisuk
5 Replies

6. Shell Programming and Scripting

appending data to file

Hi. I wrote a very simple script and it doesn't work :( It is supposed to go to a certain directory, execute some command and append the output to the file "expo.dat" what it does is that it writes to the file only one entery. I dont know if Im using the write synthax for "append". Here is... (3 Replies)
Discussion started by: Enigma08
3 Replies

7. Shell Programming and Scripting

appending space to variable

Hi I need to write a script where there the user enters 3 input parameter variable number the program should ask the user left or right if it is left , the number specified that many spaces should be added to the value in front of the value and saved in the samee variable itself and if it is... (5 Replies)
Discussion started by: viv1
5 Replies

8. Shell Programming and Scripting

Appending data at the first and last line of a file

Hi, Am trying to write a shell script which will append a header and a footer to an existing file. Header will contain details like the current date while the footer will contain the no: of records listed in the file. I know we can use the CAT command, but i have no clue abt the syntax to... (4 Replies)
Discussion started by: brainstormer
4 Replies

9. UNIX for Advanced & Expert Users

Convert Binary data to ascii data

Friends, I've tried on solaris, but I could n't get ascii data dd if=binaryinputfile bs=1 skip=3800 count=4 | od -t u4 output : INDBU3:/usr/users/FTAMUSER/kk $ dd if=SMP20041006173649188151 bs=1 skip=3800 count=4 | od -t u4 4+0 records in 4+0 records out 0000000 0000000000 0000004... (4 Replies)
Discussion started by: krishna
4 Replies

10. UNIX for Dummies Questions & Answers

help on appending data to existing data

I need to know how to record the hostname, date/time and all of the process and send it all to one file. I know that the commands I need are hostname, date and ps but I don't know how to do them all and send them all to the same file. Please help! (1 Reply)
Discussion started by: precious51980
1 Replies
Login or Register to Ask a Question