473,569 Members | 2,916 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 #1
13 2347
"jt" <jt****@hotmail .com> writes:
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?


It's logically impossible. A "string" is, by definition, "a
contiguous sequence of characters terminated by and including the
first null character" (C99 7.1.1p1). If a sequence of characters
includes a null character other than at the end, it's not a string.

Since strcat() works with strings, it can't work with the sequences
you're using (as I'm sure you've discovered.

Since you don't have the trailing '\0' to mark the end of your
sequence, you have to have some other way of specifying how long it
is. Once you've done that, you can probably use memcpy() (or
memmove() if there's a possibility of overlap) to copy things around.
The required arguments to memcpy() are determined by the lengths of
the sequences you want to copy. Since you haven't told us how that's
defined, we can't provide more details.

Of course, you still have the same memory allocation issues (making
sure the target is big enough to hold the concatentated result) that
you have with real strings.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #2

"jt" <jt****@hotmail .com> wrote in message
news:h1******** ***********@tor nado.tampabay.r r.com...
I can't seem to find a way to concatenate strings that have nulls within
the string.
Of course not. By definition, a string cannot contain
embedded null characters. The null character ('\0')
is used to denote the end of a 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?


Stop thinking of them as strings. They're simply arrays
of characters. Then look up 'memcpy()' and 'memmove()'.
(Observe the notations in the documentation about overlapping
areas of memory).

-Mike
Nov 15 '05 #3
>I can't seem to find a way to concatenate strings that have nulls within the
string.
If it has nulls internal to it, it's *NOT* a string.
How do you find the end or length of such a non-string?

I have a string
No, you don't. It's NOT a string!
that I need another string
Another *NON*-string!
that has nulls in it and what to
append
the 2nd string, 3 string and so forth to the 1st string.
They AREN'T STRINGS!!
Any ideas how to go about this?


Assuming:
You have as many ByteSequences ByteSequence1, ByteSequence2, ...
as you need, of length ByteSequence1Le ngth, ByteSequence2Le ngth, ...
and that there is sufficient storage at the end of ByteSequence1 to
hold the rest of them:

memcpy(ByteSequ ence1+ByteSeque nce1Length, ByteSequence2, ByteSequence2Le ngth);
memcpy(ByteSequ ence1+ByteSeque nce1Length+Byte Sequence2Length ,
ByteSequence3, ByteSequence3Le ngth);
memcpy(ByteSequ ence1+ByteSeque nce1Length+Byte Sequence2Length +ByteSequence3L ength,
ByteSequence4, ByteSequence4Le ngth);
...

NewByteSequence 1Length = ByteSequence1Le ngth + ByteSequence2Le ngth + ... ;
Gordon L. Burditt
Nov 15 '05 #4
Keith Thompson <ks***@mib.or g> wrote:
It's logically impossible. A "string" is, by definition, "a
contiguous sequence of characters terminated by and including the
first null character" (C99 7.1.1p1). If a sequence of characters
includes a null character other than at the end, it's not a string.


But it would be acceptable to refer to the array OP mentioned as a
series of contiguous strings, would it not? The sequence as a whole
is not a string, but the subsequences are, yes?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #5
>> It's logically impossible. A "string" is, by definition, "a
contiguous sequence of characters terminated by and including the
first null character" (C99 7.1.1p1). If a sequence of characters
includes a null character other than at the end, it's not a string.


But it would be acceptable to refer to the array OP mentioned as a
series of contiguous strings, would it not? The sequence as a whole
is not a string, but the subsequences are, yes?


But you still have no way to figure out when you've reached the
LAST one. And you don't know whether the last \0 is part of
the non-string.

Gordon L. Burditt
Nov 15 '05 #6

jt wrote:
I can't seem to find a way to concatenate strings that have nulls within
the string.
This is impossible. By definition, a null marks the end of a string. You
can't have nulls within a string.

Perhaps you are thinking not of a string, but an array of characters of
known length.

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.
To concatenate two arrays, use memcpy()


Any ideas how to go about this?

Thanks,
jt


--
Remove '.nospam' from e-mail address to reply by e-mail
Nov 15 '05 #7
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.
Nov 15 '05 #8
Christopher Benson-Manica <at***@nospam.c yberspace.org> writes:
Keith Thompson <ks***@mib.or g> wrote:
It's logically impossible. A "string" is, by definition, "a
contiguous sequence of characters terminated by and including the
first null character" (C99 7.1.1p1). If a sequence of characters
includes a null character other than at the end, it's not a string.


But it would be acceptable to refer to the array OP mentioned as a
series of contiguous strings, would it not? The sequence as a whole
is not a string, but the subsequences are, yes?


Only if the last character of the array happens to be a '\0';
otherwise it's a series of contiguous strings followed by an
unterminated character array.

In any case, that's probably not a useful way to look at it. They
seem to be just character arrays with '\0' being an ordinary value
with no special significance.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #9
jt

"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:9f******** ********@newsre ad3.news.atl.ea rthlink.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?
Nov 15 '05 #10

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

Similar topics

4
22840
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...
30
26996
by: priya | last post by:
Hi How to concatenate two integer Values. Example Program : #include "Port.h" #include "BinaryConversion.h" # include "iostream.h"
2
4335
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...
0
1812
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...
37
2425
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
10521
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...
4
4457
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...
23
6548
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
2726
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...
0
7693
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...
0
7605
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...
1
7665
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...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
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...
0
5217
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
933
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...

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.