Re: Convert char array to char* in managed C++

  • Thread starter Carl Daniel [VC++ MVP]
  • Start date
C

Carl Daniel [VC++ MVP]

YW said:
Here is my code:

char str[1000];
char *tmp = String;
strcpy(str, "abc...."); // "abc,,," ia a char string
with more than 500 characters


My problem is: the char* tmp only gets the first 256
characters from the char array str.

Are you sure? Perhaps the debugger is only showing you the first 256
characters? Does the literal string contain any embedded nulls (\0)? If
so, strcpy will stop at the first embedded null.

You also haven't shown any code at all that references tmp, or clarifies
what "String" is.

-cd
 
Y

YW

Sorry, the code should be

char str[1000];
char *tmp = str;
strcpy(str, "abc...."); // "abc,,," ia a char string
with more than 500 characters


My problem is: the char* tmp only gets the first 256
characters from the char array str.

I am sure the string "abc...." has no '\0' in the middle.
 
C

Carl Daniel [VC++ MVP]

YW said:
Sorry, the code should be

char str[1000];
char *tmp = str;
strcpy(str, "abc...."); // "abc,,," ia a char string
with more than 500 characters


My problem is: the char* tmp only gets the first 256
characters from the char array str.

By what measure? tmp is simply a pointer - it points to the start of str -
in other words, it doesn't "get" anything. It would help if you could show
a complete example and explain what you're trying to do and how you're
observing that "tmp only gets the first 256 characters".

-cd
 
Y

YW

Thank you so much for your help.

I think I found the problem. The char* tmp actually have
all the characters in the array, it's just the debug
window only shows the first 256 chars.
 

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

Top