For very many reasons this cannot possibly be your code, because it would never compile
- There is no
txt
array anywhere.
- The
for
loop syntax is wrong.
these are only two, but they are a lot for such little code.
Another question that can be asked is
- What is the C interpreter?
But the most important thing in your code is
- There is no good reason to copy the strings!
You can simply use the original pointers and pass them to the lr_output_message()
function and also note that you don't need the length of the string since probably lr_output_message()
is expecting a c-string defined as a sequence of non-null bytes followed by a null byte. Bear in mind that copying a string is an expensive operation and if you can avoid it you should.
The access violation could be for many reasons, you are reading a third element in an array of only two. You are copying a very long string to an array that doesn't have enough space for it.
But from the posted code it's not possible to know which one is the real problem, because the code you posted would not even compile.
Also, allocating an array of an arbitrary size "probably" big enough for the target string is a bad practice IMHO. You should have a clear limit for the size of the array, or compute it at runtime. It actually depends on many things but, in general you should either know that the string is guaranteed to fit the array or, check at runtime.