strcat() -- driving me nuts --what am I doing wrong

I am giving up.... after 10 hours trying to get passed this issue... :frowning:

I'd like to build a string from integers and strings, like so:

temp = year() + "-" = month() + "-" = day();

I am reading a serial port, until \n and then extract what I need in the order I want it:

    char recordIn[RECORD_IN_ARRAY_SIZE];          // one record in from BMS; every second a new one
    char recordOut[RECORD_OUT_ARRAY_SIZE];        // one record out from BMS

[/code]

and can build my string

        char charBuf[7];
        dtostrf(currentTemp, 6, 2, charBuf);      // convert float to char
        strcat(recordOut, ",");                   // add delimiter
        strcat(recordOut, deblank(charBuf));      // add temperature

        // get field 7 -- ERR error value         // ERR
        strcat(recordOut, ",");                   // add delimiter
        strcat(recordOut, arrValues[6]);          // add error value

        // get field 12 -- TIM value              // TIM = BMS record count (0-45)
        strcat(recordOut, ",");                   // add delimiter
        strcat(recordOut, arrValues[11]);         // add received record count

... but for the life of it, cannot build the date string without getting an error.

this works:

        strcat(recordOut, "2017-03-11");

this doesn't:

        strcat(recordOut, datumToString2());

with

String datumToString2(){
  // date time to string
  char buffer[20];
  snprintf(buffer, sizeof buffer, "%d", year());
  return buffer;
}

creating an error:

cannot convert 'String' to 'const char*' for argument '2' to 'char* strcat(char*, const char*)'

with

char datumToString2(){
  // date time to string
  char buffer[20];
  snprintf(buffer, sizeof buffer, "%d", year());
  return buffer;
}

creating a warning

invalid conversion from 'char*' to 'char' [-fpermissive]

this does not work

String datumToString(){
  // date time to string
  String tmp= "";

  tmp = String(year())         + "-";
  tmp = tmp + String(month())  + "-";
  tmp = tmp + String(day())    + " ";
  tmp = tmp + String(hour())   + ":";
  tmp = tmp + String(minute()) + ":";
  tmp = tmp + String(second());

  return tmp;
}

Any hints appreciated. Thanks.

Can you please post a complete program showing the problem. Your snippets show a mixture of Strings and strings and I for one am confused as to exactly what you are doing and how.

Before I saw your replies, I tried this:

        char tmp[5];
        //snprintf(tmp, "%d", year());
        sprintf(tmp, "%d", year());
        strcat(recordOut, tmp);
        strcat(recordOut, "-");

        tmp[0] = '\0';
        sprintf(tmp, "%d", month());
        strcat(recordOut, tmp);
        strcat(recordOut, "-");

        tmp[0] = '\0';
        sprintf(tmp, "%d", day());
        strcat(recordOut, tmp);
        strcat(recordOut, " ");

        tmp[0] = '\0';
        sprintf(tmp, "%d", hour());
        strcat(recordOut, tmp);
        strcat(recordOut, " ");

        tmp[0] = '\0';
        sprintf(tmp, "%d", minute());
        strcat(recordOut, tmp);
        strcat(recordOut, " ");

        tmp[0] = '\0';
        sprintf(tmp, "%d", second());
        strcat(recordOut, tmp);
        
        tmp[0] = '\0';

which did not work, but rattled the memory.
the I tried this, and it worked:

        char tmp[20];
        //snprintf(tmp, "%d", year());
        sprintf(tmp, "%d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second());
        strcat(recordOut, tmp);
        tmp[0] = '\0';

I did not post the whole code, as it has some 500 lines, hence, I showed what I felt mattered, which is the definition of recordOut[] and some of the strcat() commands which did work.

I have the suspicion, that while this works now, it works by coincidence and not by design, as I struggle to understand the difference between char, char* and all the C strings.

By not providing a complete program to test, even if it was a small example written to show the problem, it is very difficult to comment. You say

I showed what I felt mattered, whihc is the definiiton of recodOut[]

but you did not show where or how RECORD_OUT_ARRAY_SIZE was defined. Do you see how that could be important to know ?

Code was to big to post... limit 9000 chars; code has 19,000
BTW: the array was 80 chars

UKHeliBob:
By not providing a complete program to test...

Here is goes in two lots:

/*
  Read current log data via Serial from evPower RAPS battery management system
  publish MQTT data/log string

  170311 MaxG v1.11 - optimise code
  170309 MaxG v1.10 - now back to UNO, but w/o RTC unsing NTP instead

  170118 MaxG v1.03 - now on sloeber IDE
  160824 MaxG v1.02 - now on ATMEGA, incl MQTT
  150527 MaxG v0.1  - PoC on Arduino UNO

  BMS sends at 4800 baud; uni-directional; only RX required

  Ethernet board settings
  Arduino UNO pins: 10 (CS), 11 (MOSI), 12 (MISO), 13 (SCK)

  MQTT: The keep-alive interval is set to 15 seconds by default. This is configurable
  via MQTT_KEEPALIVE in PubSubClient.h
*/
// -----------------------------------------------|--------------------------------
#include <Wire.h>                                 // I2C library
#include <OneWire.h>                              // OneWire library for Dallas DSB etc.
#include <DallasTemperature.h>                    // DS18B20 library
#include <SPI.h>                                  // SPI for Ethernet board
#include <Ethernet.h>                             // Ethernet library
#include <EthernetUdp.h>                          // UDP
#include <TimeLib.h>                              // https://github.com/PaulStoffregen/Time
#include <PubSubClient.h>                         // MQTT client
#include <SoftwareSerial.h>                       // software via serial port

#define DEBUG
#define DEBUG_TIMERx

#define MQTT_MAX_PACKET_SIZE 250                  // configurable in PubSubClient.h; def = 128
#define MQTT_SOCKET_TIMEOUT  120                  // configurable in PubSubClient.h; def =  15

#define PIN_LED_MQTT_CONNECTED  4                 // MQTT connection LED (green)

const int PIN_RX                      =    8;     // RX is digital pin 10 (connect to TX of RAPS)
const int PIN_TX                      =    9;     // TX is digital pin 11 (connect to RX of RAPS)

const unsigned int BAUD_RATE_HW       = 9600;     // hardware serial baud rate
const unsigned int BAUD_RATE_SW       = 4800;     // software serial baud rate

unsigned long lastReconnectAttempt           =      0;
const unsigned long MQTT_RECONNECT_INTERVAL  =  10000;    // in ms

const byte PIN_DS18B20                =    2;     // DS18B20 pin on Arduino board
const byte PIN_SOC_OUT                =    3;     // analog SoC pin
const byte RECORD_IN_ARRAY_SIZE       =  120;     // array size in  = 119 + \0
const byte RECORD_OUT_ARRAY_SIZE      =   70;     // array size out =  69 + \0
const byte TEMP_PRECISION             =   11;     // sensor precision, here 11bit
const unsigned int MQTT_PORT          = 1883;     // MQTT server port number
const unsigned int BATT_CAPACITY_AH   =  400;     // battery capacity in Ah

const int NTP_PACKET_SIZE             =   48;     // NTP time is in the first 48 bytes of message
const int timeZone                    =   10;     // AEST
const unsigned int LOCAL_NTP_PORT     = 8888;     // local port to listen for UDP packets

const char MQTT_PUB_BMS[]                 = "ArgyleCourt/Shed/Tower/BMS2";
const char MQTT_PUB_BMS_SOC[]             = "ArgyleCourt/Shed/Tower/BMS2/SOC";
const char MQTT_PUB_BMS_BatteryPower[]    = "ArgyleCourt/Shed/Tower/BMS2/BatteryPower";
const char MQTT_PUB_BMS_BatteryCapacity[] = "ArgyleCourt/Shed/Tower/BMS2/BatteryCapacity";
const char MQTT_CONNECT_ID[]              = "arduinoClient0A";  // last two hex tuples of MAC address

unsigned long prevMillis              = 0;
unsigned int loopCounter              = 0;        // incremented with every record being read
float currentTemp                     = 0;        // holds current temperature value
int recordInByteCount                 = 0;        // counter for bytes received
float controlValueOut                 = 0;        // SOC value for Selectronic input
float controlValueOutOld              = 0;        //

byte mac[] = { 0x4D, 0x61, 0x78, 0x47, 0x30, 0x41 };  // 6 hex digit MAC: reads MaxG3A
IPAddress server(192, 168, 1, 5);                 // MQTT broker server
IPAddress timeServer(192, 168, 1, 5);             // rPiAutomation
byte packetBuffer[NTP_PACKET_SIZE];               // Buffer to hold incoming & outgoing packets

OneWire oneWire(PIN_DS18B20);                     // set OneWire Reference
DallasTemperature sensors(&oneWire);              // init DS18B20
SoftwareSerial SerialPortOne(PIN_RX, PIN_TX);

EthernetClient ethClient;                         // eth
PubSubClient mqttClient(ethClient);               // MQTT
EthernetUDP Udp;
time_t prevDisplay = 0;                           // when the time was last displayed


// -----------------------------------------------|--------------------------------
void setup() {                                    // runs once

  Ethernet.begin(mac);                            // get IP config from DHCP
  delay(1000);                                    // time to establish connection
  mqttClient.setServer(server, MQTT_PORT);        // mosquitto broker server and port
  //mqttClient.setCallback(callback);               // MQTT call back handling

  // set digital pins to output and initialise to low (OFF)
  pinMode(PIN_LED_MQTT_CONNECTED, OUTPUT);        // LED for MQTT connection
  digitalWrite(PIN_LED_MQTT_CONNECTED, LOW);

  pinMode(PIN_RX, INPUT);                         // assign receive pin
  pinMode(PIN_TX, OUTPUT);                        // assign transmit pin (not required for this app)

  Serial.begin(BAUD_RATE_HW);                     // start hardware serial port with 9600 bps
  SerialPortOne.begin(BAUD_RATE_SW);              // start software serial port with 4800 bps

  Wire.begin();                                   // start I2C protocol
  sensors.setResolution(TEMP_PRECISION);          // set sensor resolution
  sensors.begin();                                // start DS18B20

  sensors.requestTemperatures();                  // read temperature sensor
  currentTemp = sensors.getTempCByIndex(0);       // read temperature sensor

  Udp.begin(LOCAL_NTP_PORT);
  setSyncProvider(getNtpTime);
}

The code could have been attached, or you could have whittled the code down until you had either a solution or a minimal sketch which could be posted, and tested by others.

reducing it presents the same problem, as in raising questions and what about this and that. :slight_smile:

the incoming record looks like this:

VLT=53.0, AMP=-30.2, AHR=-10, SOC=98, TMP=136, STS=192, ERR=0, AHM=400, RAW=3793, AAV=0, AZP=4095, TIM=0

the rest...

// -----------------------------------------------|--------------------------------
void loop() {

  unsigned long timeStamp = millis();             // memorise current time

  if (!mqttClient.connected()) {
    // try establishing a connection to the MQTT server

    if (timeStamp - lastReconnectAttempt > MQTT_RECONNECT_INTERVAL) {
      lastReconnectAttempt = timeStamp;
      digitalWrite(PIN_LED_MQTT_CONNECTED, LOW);

      if (reconnect()) {                          // Attempt to reconnect
        lastReconnectAttempt = 0;
        digitalWrite(PIN_LED_MQTT_CONNECTED, HIGH);
      }
    }
  } else {
    mqttClient.loop();                            // maintain connection & check for incoming messages

    char recordIn[RECORD_IN_ARRAY_SIZE];          // one record in from BMS; every second a new one
    char recordOut[RECORD_OUT_ARRAY_SIZE];        // one record out from BMS

    // while there is data coming in through the serial port,
    // ... read it, work it, and send it out via MQTT
    while (SerialPortOne.available() > 0) {
      char inByte = SerialPortOne.read();         // read byte

      if (recordInByteCount < RECORD_IN_ARRAY_SIZE) {
        // select the bytes we want = digits and .,-
        if (isdigit(inByte) || inByte == '.' || inByte == ',' || inByte == '-') {
          recordIn[recordInByteCount] = inByte;   // add byte received to array
          recordInByteCount++;                    // increment byte counter
          recordIn[recordInByteCount] = '\0';     // add \o to end of array
        }
      }

      if (inByte == '\n') {                       // if EOL send buffer
        /*
         * example record received by serial:
         * Volt      Ampere     AmpereHours
         *                               State of Charge
         *                                       Temperature
         *                                                Status   Error
         * VLT=53.0, AMP=-30.2, AHR=-10, SOC=98, TMP=136, STS=192, ERR=0,
         *        1          2        3       4        5        6      7
         *        0          1        2       3        4        5      6
         * AHM=400, RAW=3793, AAV=0, AZP=4095, TIM=0
         *       8         9     10        11     12
         *       7         8      9        10     11
         *
         * TIM counts from 0-45; can be used to check if all records have been received
         */

        loopCounter++;                            // increment temp reading loop counter

        /*
         * select values to show
         * recordIn now contains: 53.0,-30.2,-10,98,136,192,0,400,3793,0,4095,42
         * 56.0,0.5,-0,100,830,960,0,400,4100,10240,4095,20
         * 08/07/2016 14:31:04,56.0,0.5,-0,100,24.75,0,
         * 56.0,0.6,-0,100,828,960,0,400,4101,10752,4095,21
         * 08/07/2016 14:31:06,56.0,0.6,-0,100,24.75,0,
         * 56.0,0.5,-0,100,827,960,0,400,4100,11264,4095,22
         * 08/07/2016 14:31:07,56.0,0.5,-0,100,24.75,0,
         */

        //Serial.println(recordIn);                 // adds 28ms on UNO
        //Serial.println(strlen(recordIn));

        // create array of BMS values
        int arrayElements = 12;                   // number of array values
        char *arrValues[arrayElements];           // array holding values

        arrValues[0] = strtok(recordIn, ",");     // get first token

        for (int j = 1; j <=arrayElements; j++) {
          arrValues[j] = strtok(NULL, ",");       // walk through other tokens
        }

        /*
         * build recordOut like so:
         * YYYY-MM-DD HH:mm:ss,55.9,1.2,-0,100,31.06,0,16
         * 12345678901234567890123456789012345678901234567890
         *          1         2         3         4         5
         */

        char tmp[20];
        //snprintf(tmp, "%d", year());
        sprintf(tmp, "%d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second());
        strcat(recordOut, tmp);
        tmp[0] = '\0';

        for (int i = 0; i <= 3; i++) {            // VLT, AMP, AHR, SOC
          strcat(recordOut, ",");                 // add delimiter
          strcat(recordOut, arrValues[i]);        // add value
        }

        controlSOC(atoi(arrValues[2]));           // feed in AHR to calc SOC

        if (loopCounter == 60) {                  // every 60 records (~60s) read temperature sensor
          sensors.requestTemperatures();          // get temperatures
          currentTemp = sensors.getTempCByIndex(0); // read 1st temperature sensor
          loopCounter = 0;                        // reset
        }

        // dtostrf(floatVar, minStringWidthIncDecimalPoint, numVarsAfterDecimal, charBuf);
        // here: temp float value, -12.34 (6), 2, buf = 6 + \0
        char charBuf[7];
        dtostrf(currentTemp, 6, 2, charBuf);      // convert float to char
        strcat(recordOut, ",");                   // add delimiter
        strcat(recordOut, deblank(charBuf));      // add temperature

        // get field 7 -- ERR error value         // ERR
        strcat(recordOut, ",");                   // add delimiter
        strcat(recordOut, arrValues[6]);          // add error value

        // get field 12 -- TIM value              // TIM = BMS record count (0-45)
        strcat(recordOut, ",");                   // add delimiter
        strcat(recordOut, arrValues[11]);         // add received record count

        Serial.println(recordOut);
        mqttClient.publish(MQTT_PUB_BMS, recordOut);

        // if SOC has changed, push new value via MQTT, connect first if required
        if (controlValueOut != controlValueOutOld) {
          // ----- MQTT publishing -----

          // publish SoC
          char bufSOC[7];                            // 100.00 = 6 char + \0 = 7
          dtostrf(controlValueOut, 6, 2, bufSOC);
          mqttClient.publish(MQTT_PUB_BMS_SOC, deblank(bufSOC));
          controlValueOutOld = controlValueOut;

          // publish battery power (kW)
          float batteryPower;

          if (controlValueOut != 100 ) {
            batteryPower = (atoi(arrValues[0]) * atoi(arrValues[1]) * 1.0);
          } else {
            /*
            correct batteryPower to 0, because it may reach a SOC of 100% while still
            showing a charge of up to 5kW -- Once the SoC has reached 100% the data
            is no longer updated via MQTT, until the SoC changes again
            */
            batteryPower = 0;
          }

          char bufBatteryPower[7];                  // 5000.0 = 6 char + \0 = 7
          dtostrf(batteryPower, 6, 2, bufBatteryPower);
          mqttClient.publish(MQTT_PUB_BMS_BatteryPower, deblank(bufBatteryPower));

          // publish battery capacity (kW)
          float batteryCapacity = (20000 - (atoi(arrValues[0]) * abs(atoi(arrValues[2])) * 1.0)) / 1000;
          char bufBatteryCapacity[8];               // 20000.0 = 7 char + \0 = 8
          dtostrf(batteryCapacity, 7, 2, bufBatteryCapacity);
          mqttClient.publish(MQTT_PUB_BMS_BatteryCapacity, deblank(bufBatteryCapacity));
        }

        recordIn[0]       = '\0';                   // empty array
        recordOut[0]      = '\0';                   // empty array
        recordInByteCount = 0;                      // reset byte counter
      }
    }
  }
}

// --------------------------------------------------------------------------------
void controlSOC(float controlValue) {
  /*
   * SoC value to control Selectronic SP PRO GO
   * analog out is 0-5V with 255 steps or 5/255 = 0.0196
   * 100mv ~
   * input: AHR = amp hour value for charge (+) and discharge (-) value
   *        -400 ~ 0% SoC to 0 = 100% SoC
   * Battery capacity 400 AH
   * calc: ((-AHR / AH) + 1) * 100 | (-172/400 = -0.43 - 1 = .57 * 100 = 57%
   */

  // calc AD output value
  controlValueOut = ((controlValue / BATT_CAPACITY_AH) + 1) * 100;
  analogWrite(PIN_SOC_OUT, controlValueOut * 2.56);
}

// -----------------------------------------------|--------------------------------
char * deblank(char *str) {
  // snatched; one day I will even understand it :-S
  char *out = str, *put = str;

  for (; *str != '\0'; ++str) {
    if (*str != ' ')
      *put++ = *str;
  }

  *put = '\0';
  return out;
}

// -----------------------------------------------|--------------------------------
boolean reconnect() {

  if (mqttClient.connect(MQTT_CONNECT_ID)) {
    // e.g. mqttClient.subscribe(MQTT_SUB_something);  // subscribe to hub pump demand
  }

  return mqttClient.connected();
}
cannot convert 'String' to 'const char*' for argument '2' to 'char* strcat(char*, const char*)'

strcat(destination, source) expects to append the char array pointed to by destination with a char array pointed to by source.

This is a C string manipulation tool.

We obviously cannot compile your code without installing all the libraries, so your whole code isn't useful.

Typically, you would create a minimal sketch that demonstrates your problem.

why not just build recordOut with snprintf()?

Your use of strcat here:

        sprintf(tmp, "%d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second());
        strcat(recordOut, tmp);
        tmp[0] = '\0';

is flawed.

Use strcpy instead.

The reason is that you are trying to concatenate tmp onto a string whose content you have not set. recordOut is a local variable which is not initialized so you have no reason to suppose that it has a character zero as it's first element. Your use of strcat here silently assumes that.

Alternatively, you could set it zero as you did with tmp in the snippet above. Then your use of strcat would be ok.

Remember that local variables live on the stack. What's in them when they're not initialized depends on what happened earlier in your program and will likely produce unpredictable results.

wildbill:
is flawed.

Looks like you are onto something...

Here the reduced snippet asked for by BulldogLowell:

BulldogLowell:

We obviously cannot compile your code without installing all the libraries, so your whole code isn't useful.

Typically, you would create a minimal sketch that demonstrates your problem.
[/quote]

OK, I have now created a small subset...

[code]
void setup() {
}

void loop() {
  int year = 2017;
  int month = 3;
  int day = 11;
  int hour = 22;
  int minute = 33;
  int second = 44;
  //int recordByteCount = 105;
  char recordOut[80];                      // one record out from BMS
  char recordIn[] = {"VLT=53.0, AMP=-30.2, AHR=-10, SOC=98, TMP=136, STS=192, ERR=0, AHM=400, RAW=3793, AAV=0, AZP=4095, TIM=0"};

// create array of BMS values
  int arrayElements = 12;                  // number of array values
  char *arrValues[arrayElements];          // array holding values

arrValues[0] = strtok(recordIn, ",");    // get first token

for (int j = 1; j <=arrayElements; j++) {
    arrValues[j] = strtok(NULL, ",");      // walk through other tokens
  }

/*
  * build recordOut like so:
  * YYYY-MM-DD HH:mm:ss,55.9,1.2,-0,100,31.06,0,16
  * 12345678901234567890123456789012345678901234567890
  *          1        2        3        4        5
  */

char tmp[20];
  //sprintf(tmp, "%d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second());
  //sprintf(tmp, "%d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
  //strcat(recordOut, tmp);
  tmp[0] = '\0';

strcat(recordOut, year);
  strcat(recordOut, "-");
  strcat(recordOut, month);
  strcat(recordOut, "-");
  strcat(recordOut, day);
  strcat(recordOut, " ");

for (int i = 0; i <= 3; i++) {            // VLT, AMP, AHR, SOC
    strcat(recordOut, ",");                // add delimiter
    strcat(recordOut, arrValues[i]);        // add value
  }

// get field 7 -- ERR error value        // ERR
  strcat(recordOut, ",");                  // add delimiter
  strcat(recordOut, arrValues[6]);          // add error value

// get field 12 -- TIM value              // TIM = BMS record count (0-45)
  strcat(recordOut, ",");                  // add delimiter
  strcat(recordOut, arrValues[11]);        // add received record count

Serial.println(recordOut);

recordIn[0]      = '\0';                  // empty array
  recordOut[0]      = '\0';                  // empty array
}

// -----------------------------------------------|--------------------------------
char * deblank(char *str) {
  // snatched; one day I will even understand it :-S
  char *out = str, *put = str;

for (; *str != '\0'; ++str) {
    if (*str != ' ')
      *put++ = *str;
  }

*put = '\0';
  return out;
}




but the error is not as strong as it was when I used year() in strcat(recordOut, year());

I apologise for my delayed posts... I have a fixed wireless tower problem where they gear seems to yo-yo like 10 minutes up 5 minutes down:
2017-03-11 20:43:16 down
2017-03-11 20:48:07 up
2017-03-11 20:57:30 down
2017-03-11 21:02:26 up
2017-03-11 21:11:39 down
2017-03-11 21:16:36 up
2017-03-11 21:17:36 down
2017-03-11 21:17:46 up
2017-03-11 21:25:47 down
2017-03-11 21:30:43 up
2017-03-11 21:33:24 down
2017-03-11 21:33:34 up
2017-03-11 21:40:03 down
2017-03-11 21:45:00 up
2017-03-11 21:54:13 down

And when I make a correction I get: You have exceeded the number of posts you can make in a 5 minutes period. Please try again later.
By then the link is down...
...then someone has posted, and the thing asks me to review that before posting...
...and so it goes... almost impossible to work with.

But I appreciate your help and sticking with it.

snprintf() is a safer alternative to sprintf in that it prevents writing beyond the end of the destination string. You should use snprintf, generally speaking.

It accomplishes this using the size_t argument, so using the proper function prototype in your code looks like this:

snprintf(tmp, sizeof(tmp), "%d", year());

You have persisted the same error in your small sample.

Before you strcat anything into recordOut, you need this:

  recordOut[0]      = '\0';

wildbill:
You have persisted the same error in your small sample.

Yes, I tried to keep up with you guys, wanting to present the original problem... not what I fixed in between. As I was after feedback of what was wrong.

I now understand that I had to put at least NULL into recordOut[], and what I had first, with strcat() would have worked.

Thank you all for bearing with me... I now get it how to work the posts better.

Interesting that nobody has pointed out the major problem here:

strcat(recordOut, datumToString2());

...

String datumToString2(){
  // date time to string
  char buffer[20];
  snprintf(buffer, sizeof buffer, "%d", year());
  return buffer;
}

buffer is a stack variable. As soon as datumToString2 returns, the stack frame is tossed, buffer no longer exists, and the memory it once occupied is over-written when strcat is called.

Regards,
Ray L.