Single char poniters to Cstring

M

meisterbartsch

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=*(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
 
V

Victor Bazarov

meisterbartsch said:
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=*(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
 
M

meisterbartsch

meisterbartsch said:
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=*(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


I want to put single characters (I access by knowing the pointers)
into a string (CString is a VC++ Object).

Thats all ;)
 
A

Amol

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.
 
V

Victor Bazarov

meisterbartsch said:
[..]
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
 
M

meisterbartsch

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.
 
D

Default User

Amol said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top