0

I want to copy a part of char array into a new one

void match(char* probe, char* pattern)
char* matchText;
//the char-array probe in this example is at least 12 characters long
//I'm only writing numbers in the strncopy-command to make it easier to understand
strncpy (matchText, probe + 5, 5 );

Upon running that the debugger quits with an error. What am I doing wrong?

1
  • What error is it? Are the arrays properly allocated? Commented May 8, 2012 at 17:32

1 Answer 1

3

You need to allocate memory to matchText, what you have is just an pointer.
It must have enough memory allocated using malloc(since it is a pointer) to hold the string being copied in to it, or what you get is Undefined Behavior.

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

Comments

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.