473,699 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to concatenate strings that contains has nulls?

jt
I can't seem to find a way to concatenate strings that have nulls within the
string.

I have a string that I need another string that has nulls in it and what to
append
the 2nd string, 3 string and so forth to the 1st string.

Any ideas how to go about this?

Thanks,
jt
Nov 15 '05
13 2375
In article <o4************ ********@tornad o.tampabay.rr.c om>,
jt <jt****@hotmail .com> wrote:
True, a null terminates a string. But, what if that string happen to be a
binary file?


Then it is still terminated by the first NUL character.

If you want something that is able to hold NUL characters within it,
then you are NOT using a "string". A string is DEFINED to end
at the first NUL.

If you want to work with groupings of arbitrary binary characters
that might include NUL, then you probably want to work with an array
of char (better yet, unsigned char).
C90 does not offer any mechanism to dynamically determine "the size"
[allocated? initialized? Highest entry written to? Highest entry
read from?] of an array of char. The closest it comes to that is
that if you have declared a character array (not pointer to char!)
then within the same scope you can use sizeof to get to the size:
char foo[123]; /* sizeof(foo) would be 123 * sizeof(char) */

You can't do this across scope boundaries. For example,

int baz(char myarg[]) {
return sizeof myarg;
}

void koz(void) {
char foo[123];
printf( "size of foo was: %d\n", baz(foo) );
}

This will NOT print out 123: C89 does NOT "somehow" transmit the
"real" size when it passes an object in as an argument.
(Instead, you will find that myarg is treated as a pointer to
a character, so the size printed will be the size of a char pointer.)
C99 offers a new mechanism, the variable sized array; if that is
used (and everything is passed appropriately) then you can determine
an object size at a lower level routine.
--
Watch for our new, improved .signatures -- Wittier! Profounder! and
with less than 2 grams of Trite!
Nov 15 '05 #11
On Sat, 24 Sep 2005 02:44:36 GMT, in comp.lang.c , "jt"
<jt****@hotmail .com> wrote:

"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:9f******* *********@newsr ead3.news.atl.e arthlink.net...
jt wrote:
I can't seem to find a way to concatenate strings that have nulls within
the string.
Your problem is meaningless. A null terminates a string. There is no
such thing as nulls within a string.


True, a null terminates a string. But, what if that string happen to be a
binary file?


All computer data is binary.

And anyway it doesn't matter - the definition of a string is a
sequence of characters terminated by a null. The first null is thus
the end of the string.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #12
Mark McIntyre wrote:

On Sat, 24 Sep 2005 02:44:36 GMT, in comp.lang.c , "jt"
<jt****@hotmail .com> wrote:

"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:9f******* *********@newsr ead3.news.atl.e arthlink.net...
jt wrote:
I can't seem to find a way to concatenate
strings that have nulls within
the string.

Your problem is meaningless.
A null terminates a string. There is no
such thing as nulls within a string.


True, a null terminates a string.
But, what if that string happen to be a
binary file?


All computer data is binary.


"Binary files" is standard terminology.

The standard describes two kinds of streams:
binary streams and text streams.
Those kinds of streams would go accordingly
to either binary files or text files.

N869
7.19.3 Files
[#2] Binary files are not truncated, except as defined in
7.19.5.3. Whether a write on a text stream causes the
associated file to be truncated beyond that point is
implementation-defined.

--
pete
Nov 15 '05 #13

jt wrote:
I can't seem to find a way to concatenate strings that have nulls within the
string.

I have a string that I need another string that has nulls in it and what to
append
the 2nd string, 3 string and so forth to the 1st string.

Any ideas how to go about this?

Thanks,
jt


Okay, so you want to concatenate strings, but you want to preserve null
characters? You might want to look at the string-handling code of
FreeDOS edlin (available on ibiblio or alt.sources). Also, these
wouldn't be C strings, but BLOBs (Binary Large OBjects) as they contain
the null character, so you'd need to store lengths as well.

Gregory Pietsch

Nov 15 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
22846
by: Jay Chan | last post by:
I am trying to export data from a SQLServer database into a text file using a stored procedure. I want to be able to read it and debug it easily; therefore, I want all the columns to indent nicely. This means I need to append trailing spaces to a text string (such as "Test1 ") or append leading space in front of a text string that contains a number (such as " 12.00"). Now, the stored procedure works fine when I run it in Query Analyzer....
30
27031
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
2
4347
by: HumanJHawkins | last post by:
The following query works perfectly (returning all words on a list called "Dolch" that do not contain a form of "doing"): SELECT 'Dolch' AS , dbo.Dolch.vchWord FROM dbo.Dolch LEFT OUTER JOIN dbo.CombinedLexicons ON CONTAINS(dbo.Dolch.vchWord, 'FORMSOF(INFLECTIONAL, "doing")') WHERE (dbo.CombinedLexicons.vchWord IS NULL) However, what I really want to do requires me to piece two strings together,
0
1820
by: LesM | last post by:
This is a change of behaviour between Access 2000 SP3 and Access 2002 SP3. I have Progress table that is linked via ODBC into Access using OpenLink Lite for Progress 9.0b. For over a year, using Access 2000 under Win98, I have been running a Make Table or Append query against this ODBC table and producing an extracted Access table. Any fields that are NULL on the source ODBC table show as NULL on the output table. The query also has an...
37
2449
by: MLH | last post by:
For example: Nz(,0) returns "300" if the value in field is 300 (currency data type) and "0" if the value is zero or null. I get strings in the query output - they are all left aligned and I cannot add them without first converting them to values. What might be causing this?
3
10538
by: Lars Tackmann | last post by:
Hi - I need a function to concatenate a variable number of strings. I have two ideas but cannot deside which way to go. 1) use the "stdarg" macros - if i use these macros it will be easy to step through the strings, but as I see it (and I may be wrong here)I need to pass the number of strings to the function - which is difficult in this context. 2) using a pointer array as argument to the function. Here the length is again a problem -...
4
4472
by: Barry | last post by:
Hi all! I support a rather large production EDI application with a number of C programs, and I ran across a very interesting problem. I have some code that used to work just fine for years, and now all of a sudden it doesn't work any more. The input to the program did not change at all (even ran it through a binary browser to make certain there were no hidden chars or something strange) and the program has not been recompiled in years....
23
6573
by: tejasm | last post by:
Hi, I have - char* c="file.txt" char* con="AB.txt"; I want to replace and concatenate the above to get a new string- "fileAB.txt"
2
2738
by: CharlesL | last post by:
I am trying to handle binary strings in php. I get a binary output initialization vector from mcrypt as such: from mcrypt: $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); This output may have padded nulls at the end which are significant. I would like to convert all characters including all padding nulls at end and convert it in a string to be saved into a database in such a way
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.