473,414 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

transforming from a non-null terminated string into a null terminatedstring

If I'm being supplied with a char* that is not null-terminated, is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?
Aug 12 '08 #1
5 1920
ssylee said:
If I'm being supplied with a char* that is not null-terminated,
A char * is a pointer to a single character. Presumably you mean that the
char * points to the first character in an arbitrarily long sequence, a
sequence which ought to have a null terminator but, for one reason or
another, has not. My answer is based on that understanding.
is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?
If you know where the null terminator is supposed to go, you can put one
there. s[n] = '\0';

If you don't, you can't, because a non-null-terminated sequence of chars
will not of itself provide you with that information (in the general
case). I am ignoring clever-clever answers such as:

char arr[55] = "The terminator belongs in place of this trailing colon:";
char *p = arr;

for what I hope are obvious reasons.

So no, you can't hope for the language to tell you where your data ends -
it's your job to know that.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 12 '08 #2
ssylee wrote:
If I'm being supplied with a char* that is not null-terminated, is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?
It depends. One piece of information that you *must* know is *where* to
place the null character, i.e., you must know the length of the char
array that your char* points at. Otherwise you'll either truncate your
array or write beyond it's bounds.

What abstract information have you been given about the char*?

Aug 12 '08 #3
On Aug 12, 12:15*pm, santosh <santosh....@gmail.comwrote:
ssylee wrote:
If I'm being supplied with a char* that is not null-terminated, is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?

It depends. One piece of information that you *must* know is *where* to
place the null character, i.e., you must know the length of the char
array that your char* points at. Otherwise you'll either truncate your
array or write beyond it's bounds.

What abstract information have you been given about the char*?
Thank you for your replies. I found out that there is an information
that I have missed out in terms of the ASCII to UNICODE conversions.
So I guess this problem is solved.
Aug 12 '08 #4
ssylee wrote:
If I'm being supplied with a char* that is not null-terminated, is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?
It depends on what that "abstract information" is. If it includes the
length of the information you want in the string, or if it indicates
that the 1st (or 2nd or some other specific ordinal) occurrence of a
certain character is the end of the wanted resultant string, obviously
it is trivial. Otherwise, it is near impossible.

Aug 12 '08 #5
ssylee wrote:
>
If I'm being supplied with a char* that is not null-terminated,
is it impossible to transform it into a null terminated char*
with only abstract information about the char* information?
What specifies the length of the string you have stored in there?

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

Aug 12 '08 #6

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

Similar topics

5
by: Jody Greening | last post by:
Transforming with XSLT, Grouping elements until difference found. I am seeking some help with the following problem, I am fairly new at XSLT transformations, and my problem may lie in looking at...
4
by: mikeyjudkins | last post by:
I have an XML file containing localized strings in 9 languages, encoded in Unicode (UTF-8). Im trying to parse this XML document via XSLT (Apache Xalan) to selectively render localized strings...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
5
by: Daniel Crespo | last post by:
Is there a built-in method for transforming (1,None,"Hello!") to 1,None,"Hello!"? Thanks
4
by: Showjumper | last post by:
I am using the NITF DTD for my xml files and i need to use 2 xsl files to do the transform: one for the <body.head> and the second for the <body.content>. I've got this so far for transforming...
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
6
by: Adam Clauss | last post by:
I have a list of points (their coming in as decimal types, I can convert to PointF) that I am trying to draw to a form. Unfortunately, the coordinate system these points are coming from is not...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
by: mannem | last post by:
I have a problem in accessing the values while transforming an XML using XSLT BODY { FONT: x-small 'Verdana'; MARGIN-RIGHT: 1.5em } .c { CURSOR: hand } .b { FONT-WEIGHT: bold; COLOR: red;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.