473,503 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Single char poniters to Cstring

Hi NG,

I have got a starting pointer of a char series (mxArrayToString(pa)).
I also know the length (number of elements by mxGetNumberOfElements) I
want to read.

How do I get a Cstring from those Informations?

I had the Idea to do the following

char* Ps = new char[NumberOfElements(pa)+1];
for (int i=0;i<mxGetNumberOfElements(pa);++i)
{
Ps[i]=*(mxArrayToString(pa)+i*sizeof(char));
TRACE("%c",*(mxArrayToString(pa)+i*sizeof(char))); //debug
}

but this does not work for me. Afterwards I wanted to get a Cstring
from "Ps"...

Any Ideas how to do it right?

Best regards

Patrick

Jun 15 '07 #1
6 3456
meisterbartsch wrote:
I have got a starting pointer of a char series (mxArrayToString(pa)).
Not sure what "a char series" is. Could you explain?
I also know the length (number of elements by mxGetNumberOfElements) I
want to read.
Did you write the 'mx' functions? What are they? What's "pa"? How
is it declared/defined?
How do I get a Cstring from those Informations?
What's a Cstring?
>
I had the Idea to do the following

char* Ps = new char[NumberOfElements(pa)+1];
for (int i=0;i<mxGetNumberOfElements(pa);++i)
{
Ps[i]=*(mxArrayToString(pa)+i*sizeof(char));
TRACE("%c",*(mxArrayToString(pa)+i*sizeof(char))); //debug
}

but this does not work for me. Afterwards I wanted to get a Cstring
from "Ps"...

Any Ideas how to do it right?
Nope. Not enough information. Sorry.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 15 '07 #2
On 15 Jun., 14:59, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
meisterbartsch wrote:
I have got a starting pointer of a char series (mxArrayToString(pa)).

Not sure what "a char series" is. Could you explain?
I also know the length (number of elements by mxGetNumberOfElements) I
want to read.

Did you write the 'mx' functions? What are they? What's "pa"? How
is it declared/defined?
How do I get a Cstring from those Informations?

What's a Cstring?
I had the Idea to do the following
char* Ps = new char[NumberOfElements(pa)+1];
for (int i=0;i<mxGetNumberOfElements(pa);++i)
{
Ps[i]=*(mxArrayToString(pa)+i*sizeof(char));
TRACE("%c",*(mxArrayToString(pa)+i*sizeof(char))); //debug
}
but this does not work for me. Afterwards I wanted to get a Cstring
from "Ps"...
Any Ideas how to do it right?

Nope. Not enough information. Sorry.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I want to put single characters (I access by knowing the pointers)
into a string (CString is a VC++ Object).

Thats all ;)

Jun 15 '07 #3
Patrick why don't you use built in library functions?
Like strdup() in <cstring>
also why do you need mxArrayToString()?
if it is like this
char a[20];
then following code must be valid
char* pa = a;

further you are doing mess with the pointers, because you don't need
to multiply the sizeof to the pointer to go to the next element the
compiler will do for you.

for example the line
TRACE("%c",*(mxArrayToString(pa)+i*sizeof(char))); //debug

can simply be written as
TRACE("%c",*(pa+i)); //debug

Finally you don't even need all this if you use the C++ standard
library string.

Hope I've interpreted what you want to say and if so helped you to
solve the problem.

Jun 15 '07 #4
meisterbartsch wrote:
[..]
I want to put single characters (I access by knowing the pointers)
into a string (CString is a VC++ Object).
CString is [considered] unknown in this newsgroup, unless you provide
its definition, because it's not a standard class. You might have
better luck asking in the newsgroup with "MFC" in its name.

If you'd like to continue posting here I suggest you first visit the
FAQ, especially section 5. http://www.parashift.com/c++-faq-lite/

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 15 '07 #5
On 15 Jun., 15:13, Amol <amolj.1...@gmail.comwrote:
Patrick why don't you use built in library functions?
Like strdup() in <cstring>
also why do you need mxArrayToString()?
if it is like this
char a[20];
then following code must be valid
char* pa = a;

further you are doing mess with the pointers, because you don't need
to multiply the sizeof to the pointer to go to the next element the
compiler will do for you.

for example the line
TRACE("%c",*(mxArrayToString(pa)+i*sizeof(char))); //debug

can simply be written as
TRACE("%c",*(pa+i)); //debug

Finally you don't even need all this if you use the C++ standard
library string.

Hope I've interpreted what you want to say and if so helped you to
solve the problem.
Thank you very much... I cleaned the mess first of all.

I am going to check what string (STL) could do for me.

Jun 15 '07 #6
Amol wrote:
Patrick why don't you use built in library functions?
Like strdup() in <cstring>
There is no such function defined in the standard library.

Brian
Jun 15 '07 #7

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

Similar topics

6
24497
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
14
3756
by: Toro | last post by:
1) say, CString b; char * a; how do I assign b into a ? strcpy(a,b) has no problem in compiling but I don't get what I want. 2) I used char ** argv
9
12197
by: Fausto Lopez | last post by:
I'm getting the following error: 'strlen' : cannot convert parameter 1 from 'class CString' to 'const char *' when I try to compile the following code: HRESULT AnsiToUnicode(CString pszA,...
5
14054
by: Tim Wong | last post by:
All: I am trying to convert a CString value to an unsigned char array. I found some code online that will allow me to compile, but when I try to print out...i get a whole mess. /*Begin Code*/...
3
9125
by: nsyforce | last post by:
What is the correct way to convert a const char* to a CString? I'm somewhat of a newbie and have tried several ways. While they all convert ok, I'm using a profiler that shows a memory leak for...
4
11011
by: Cactus | last post by:
How to convert unsigned char* to CString: I wrote some function: u_char_ =55; u_char_ =66; u_char_ =77; .........=ii...... Convert_to_CS(u_char_);
1
3324
by: nd3r | last post by:
Hy! The problem, is that I tried everything I could to convert. The following examples are already useless: //Example 1: CString text; char *ch_text = new char; strcpy(ch_text,text);
1
2104
by: Sandy | last post by:
HI All, I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof service pack 2 and it works properly on my machine, but when I run the same exe on a different machine (Windows XP Prof...
1
5521
by: sunshine2007 | last post by:
Hi everybody,I am new and I am doing a project for Pocket PC using evc 3 here is my question, I have declared a STRUCT to the Binary file struct config{ int rtuid; int netid; char *...
0
7280
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
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
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...
1
5014
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
4673
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
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...

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.