2

For example I have a( char ** ptr) which includes the address of a string.

I want to put this string in a new string ptr_2 .

It is possible?

1
  • 1
    Yes, it's possible. There are many, many ways in which you can screw it up, though. Commented Dec 3, 2011 at 14:11

2 Answers 2

3

Think about it this way: when you put an asterisk in front of a pointer, you remove an asterisk from the type of the result:

ptr is char**
*ptr is char*
**ptr is char

String in C is char*, so you need to use *ptr.

Sign up to request clarification or add additional context in comments.

Comments

1

strcpy(ptr_2, *ptr) should do the trick.

*ptr gets the address of the string you want to copy and from there you can manipulate it with any of the usual string handling functions.

2 Comments

or ptr_2 = strdup(*ptr); or simply ptr_2 = *ptr;
@harp: don't forget to upvote and accept helpful questions and answers :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.