Array problem

Hi,

I want to add some characters at the end of my array, but I got some strange effects…

What am I doing wrong?

#include <MaxMatrix.h>
#include <avr/pgmspace.h>

//Change the speed
const int shift_speed = 50;
//Change the  message
char msg[] = "Dit is een MEGA LANGE test...";
//Change the number of scrolls:
const int iScroll = 0; //Number of scrolls (-1 = static, 0 = continious, 1 = one time, 2 = times, ...)
//Choose an effect (0: none, 1 = blink (only static))
const int iEffect = 1;


int data = 12;
int load = 10;
int clock = 11;
int maxInUse = 1;    //change this variable to set how many MAX7219's you'll use (Max 8!!)
MaxMatrix m(data, load, clock, maxInUse);


int NUMs;
int x = 0;

byte buffer[10];

void setup()
{
  m.init();
  m.setIntensity(15);
  Serial.begin(9600);
  
strncat(msg, " New Charaters",14);

NUMs = sizeof(msg);

}

void loop(){
 
 if (x < iScroll || iScroll == 0){
    for (int i=0; i < NUMs ; i++){
      printCharWithShift(msg[i]);
    }
    if (iScroll > 0) x = x +1;
  }
}



void printStringWithShift(char* s){
  while (*s != 0)
  {
    printCharWithShift(*s);
    s++;
  }
}

void printCharWithShift(char c){
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7*c, 7);

  m.writeSprite(maxInUse * 8, 0, buffer);
  m.setColumn(maxInUse * 8 + buffer[0], 0);
   
  
  for (int i=0; i<buffer[0]+1; i++) 
  {
    delay(shift_speed);
    m.shiftLeft(false, false);
  }
}
char msg[] = "Dit is een MEGA LANGE test...";

This creates an array that is just long enough to hold your message and the terminating null. If you want to add to it later then you'll have to tell the comiler how big to make the array. If you're going to tack on 14 more characters, then the array needs to be 14 characters larger than the message.

char msg[44] = "Dit is een MEGA LANGE test...";
char msg[] = "Dit is een MEGA LANGE test...";

Creates an array of chars with a fixed length.

strncat(msg, " New Charaters",14);

Adds characters to the end of the array that is already full, thus overwriting whatever is in the memory at those locations.

So My way is the wrong way?? How can I make the msg-array dynamic AND add some characters at the end of the array

the problem is: if I don't add some extra characters (spaces) to the array, I have troubles displaying it on a led matrix in a scrolling text...

How can I make the msg-array dynamic

You can’t.
As has been suggested, make it as large as necessary in the first place.

BramWerbrouck: So My way is the wrong way?? How can I make the msg-array dynamic AND add some characters at the end of the array

Array's are fixed length.

The only way to change array lengths is to create a new array, copy the old array contents into the new array, and add the new data into the new array.

Unless you have a particular need to do that, just create a larger array in the first place, as suggested above.