Problems with strcpy changing random variables

I have the following code

struct SET {
  // Temp Settings
  uint8_t   minDayTemp;
  uint8_t   maxDayTemp;
  uint8_t   minNightTemp;
  uint8_t   maxNightTemp;
  uint8_t   canopyTemp;   //DHT22 Sensor
} settings

.
.

 char pageName0[] = "Current       ";   // "String 0" etc are strings to store - change to suit.
 char pageName1[] = "Temp          ";
 char pageName2[] = "Humidity      ";
 char pageName3[] = "Soil          ";
 char pageName4[] = "Temp Options  ";
 char pageName5[] = "Soil Options  ";
 char pageName6[] = "Light Options ";
 char pageName7[] = "Set Date/time ";

// Then set up a table to refer to your strings.

 char *pageNames[] = {	   // change "string_table" name to suit   
  pageName0,
  pageName1,
  pageName2,
  pageName3,
  pageName4,
  pageName5,
  pageName6,
  pageName7 
};

.
.

const    uint8_t cNameBufSize             = 15;   // 15 gives room for 14 characters
         char    cNameBuf[cValBufSize];           // buffer for menu child name
.
.

void    getPageName(uint8_t page) {
  Serial.print("1 settings.minDayTemp =");
  Serial.println(settings.minDayTemp);
  Serial.println(); 
  strcpy(cNameBuf, pageNames[page]);
  Serial.print("2 settings.minDayTemp =");
  Serial.println(settings.minDayTemp);
  Serial.println(); 

}

every time I call getPageName the value of settings.minDayTemp changes for some reason.

I put some debug lines in and the value of settings.minDayTemp = 1 before and 116 after the strcpy calling. How can this be possible??

I am new to c/c++ with a background in php so please be gentle if I've done something stupid.

Thanks

The code you posted is incomplete, and won't compile. Is there a minimal program you can post that will demonstrate the problem?

And, before we delve further, tell us this: What's the value of cValBufSize?

You are indeed a genius.

I have been staring at this for so long I couldn't see the error.

I had:

const    uint8_t cNameBufSize             = 15;   // 15 gives room for 14 characters
         char    cNameBuf[cValBufSize];           // buffer for menu child name

when I should of had

const    uint8_t cNameBufSize             = 15;   // 15 gives room for 14 characters
         char    cNameBuf[cNameBufSize];           // buffer for menu child name

I thought I was going crazy.

Sorry to waste your time.

I suggest you use strncpy() instead of strcpy() - it will help you avoid similar problems in future.