424,952 Members | 916 Online
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

# Single char poniters to Cstring

 P: n/a 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
6 Replies

 P: n/a 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

 P: n/a On 15 Jun., 14:59, "Victor Bazarov"

 P: n/a Patrick why don't you use built in library functions? Like strdup() in 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

 P: n/a 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

 P: n/a On 15 Jun., 15:13, Amol 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

 P: n/a Amol wrote: Patrick why don't you use built in library functions? Like strdup() in There is no such function defined in the standard library. Brian Jun 15 '07 #7

### This discussion thread is closed

Replies have been disabled for this discussion.