Problem with data type conversions

Now i don’t know exactly how to code this properly but I have an issue with the conversion of String to char Ill show you my code and maybe you can help and see major errors.

char MessageBodyWarning[127];
  if(buttonPressed == LOW){
   sprintf(MessageBodyWarning, "Button Activation at: %02d:%02d:%02d \n ", hour(), minute(), second());
  }
  else if (LeftTempCel >= 29.00){
  sprintf(MessageBodyWarning, "WARNING!!! Your Temperature is at an unstable level: s degrees Celsius \nTime of Occurance: %02d:%02d:%02d \n ", hour(), minute(), second());
  }
  else{
    String MessageBodyTotal[24];
    for (int i = 0; i < 24; i++) {
      //MessageBodyTotal[i] =( "Current time is: ");// + Time[i] + " Left Temp : " + String(LeftFloatTemp[i]) + " Right Temp: " + String(RightFloatTemp[i]));
     sprintf(MessageBodyTotal[i], "Current time is : %02d:%02d:%02d \n ", hour(), minute(), second());
    }
    String MessageBodyWarning = String(StringArrayString(MessageBodyTotal));
  
  }
  client.println(MessageBodyWarning); //Test + "\n" + Hour + "\n" + Minute + "\n" + Second
String StringArrayString(String arr[])
{
  String retStr = "";
    for (int i = 0; i < 24; i++)
      {
        retStr += arr[i] + "\n";
        //Serial.println(arr[i]);
      }
  return retStr;
}

I only posted relevant code, know that all variables have been declared. Let me know if you have any questions. Hopefully you can be helpful.

Why all the messing about with String?

As AWOL pointed out, the String object is a resource hog, as is sprintf(). I got the sprintf() version to run and it used 3652 bytes of memory. I then did it with using char arrays with strcpy() and strcat() and the same output took 2432 bytes. Unless you're using most of sprintf()'s features, it's usually overkill.

I get this, memory at this moment isn't truly an issue. but I need to be able to send it into the array and char seems to be more complexe, I don't know when to use straight char or strings or whatever. I just want my code to work

"Make it work, then make it work better."

I just want my code to work

Everyone I know... and I taught computer programming for ten years... started there. You are not alone!

But the sooner you can also want to put things together "right", the sooner you will find it all becomes a lot easier.

Also... strings vs arrays of char....

I too will "go with" the thing I think I can understand. Sometimes, though, in the course of new work, exploring new (to me) ways of doing things pays off. Arrays of char are really good, and not too horrible, once you get the hang of them. Worth the struggle.

my main issue is for some reason in my full code I can’t seem to write to an e-mail ever if i use char i stuck with sprintf, ill show my full code but blank out a few fields for privacy reasons.

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>

// this must be unique -- Ethernet Shield
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0xAB, 0x09};  

// change network settings to yours
IPAddress ip( ************** );    
IPAddress gateway( *************** );
IPAddress subnet( 255, 255, 255, 0 );

// change server to your email server ip or domain
IPAddress server( 74, 125, 24, 26 );//Gmail ServerIP

//Typical Variables
int x = 0;
int interval;
int sec5;
int days;
int hours;
int minutes;
int seconds;
int LeftTemp;
int RightTemp;
int inputPin = 8;
int buttonPressed;
int EmailStatus = 0;

float voltageR;
float voltageL;
float LeftTempCel;
float RightTempCel;
float LeftFloatTemp[24];
float RightFloatTemp[24];

String Time[24];

char MessageBodyValue[127];

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  setSyncProvider(RTC.get); // Sync RTC this is important for proper Time.
  pinMode(inputPin, INPUT_PULLUP);
  pinMode(2,OUTPUT);
  digitalWrite(2,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet); 
  delay(2000);

}

void loop()
{
  
  
  int j = 0; 

  days = day();
  hours = hour();
  minutes = minute();
  seconds = second();
  
  byte inChar;
  //determines a 5 seconds ex: 0=0  or  1,2,3,4 = 5  
  if(seconds % 5 > 0) j = 1; 
  else j = 0;
    sec5 = ((seconds /5) + j) * 5;
    interval = (((minutes % 2) * 60) + (sec5)) /5;
  x = interval -1;
  
  if (x < 0) {  //To prevent bugs forcing the hour to 11PM if it ever goes below zero
    x = 23;
  }
  
  //Calling to the Right TMP for its readings.  
    RightTemp = analogRead(A0);
    voltageR = RightTemp * 5.0;
    voltageR /= 1024.0;
    RightTempCel = (voltageR - 0.5) * 100;

    //Calling to the Left TMP for its readings.
    LeftTemp = analogRead(A1);
    voltageL = LeftTemp * 5.0;
    voltageL /= 1024.0;
    LeftTempCel = (voltageL - 0.5) * 100;
   
  
  buttonPressed = digitalRead(inputPin);
  if(buttonPressed == LOW  || LeftTempCel >= 29.00 || ((minutes % 2 == 0) && (seconds == 0)))
  {
      if(sendEmail()) Serial.println(F("Email sent"));
      else Serial.println(F("Email failed"));
  }
  if (seconds % 5 == 0) {
        SaveData();
      }
}

byte sendEmail()
{
  byte thisByte = 0;
  byte respCode;

  if(client.connect(server,25) == 1) {
    Serial.println(F("connected"));
  } else {
    Serial.println(F("connection failed"));
    return 0;
  }

  if(!eRcv()) return 0;
  Serial.println(F("Sending helo"));

// change to your public ip
  client.println(F("helo 10.40.40.20"));
  if(!eRcv()) return 0;
  Serial.println(F("Sending From"));

// change to your email address (sender)
  client.println(F("MAIL From: <email@gmail.com>"));

  if(!eRcv()) return 0;

// change to recipient address
  Serial.println(F("Sending To"));
  client.println(F("RCPT To: email@gmail.com>"));

  if(!eRcv()) return 0;

  Serial.println(F("Sending DATA"));
  client.println(F("DATA"));

  if(!eRcv()) return 0;

  Serial.println(F("Sending email"));

//E-mail Information: Sender, recipient, Subject, body message

// change to recipient address
  client.println(F("To: You <Email@gmail.com>"));
// change to your address
  client.println(F("From: Me <email@gmail.com>"));


  client.println(F("Subject: Arduino email test Muhahaha\r\n"));

  char MessageBodyWarning[127];
  if(buttonPressed == LOW){
   sprintf(MessageBodyWarning, "Button Activation at: %02d:%02d:%02d \n ", hour(), minute(), second());
  }
  else if (LeftTempCel >= 29.00){
  sprintf(MessageBodyWarning, "WARNING!!! Your Temperature is at an unstable level: s degrees Celsius \nTime of Occurance: %02d:%02d:%02d \n ", hour(), minute(), second());
  }
  else{
    String MessageBodyTotal[24];
    for (int i = 0; i < 24; i++) {
      //MessageBodyTotal[i] =( "Current time is: ");// + Time[i] + " Left Temp : " + String(LeftFloatTemp[i]) + " Right Temp: " + String(RightFloatTemp[i]));
     sprintf(MessageBodyTotal[i], "Current time is : %02d:%02d:%02d \n ", hour(), minute(), second());
    }
    String MessageBodyWarning = String(StringArrayString(MessageBodyTotal));
  
  }
  client.println(MessageBodyWarning); //Test + "\n" + Hour + "\n" + Minute + "\n" + Second

  client.println(F("."));

  if(!eRcv()) return 0;

  Serial.println(F("Sending QUIT"));
  client.println(F("QUIT"));

  if(!eRcv()) return 0;

  client.stop();

  Serial.println(F("disconnected"));

  return 1;
}

byte eRcv()
{
  byte respCode;
  byte thisByte;
  int loopCount = 0;

  while(!client.available()) {
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 10000) {
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return 0;
    }
  }

  respCode = client.peek();

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  if(respCode >= '4')
  {
    efail();
    return 0;  
  }

  return 1;
}


void efail()
{
  byte thisByte = 0;
  int loopCount = 0;

  client.println(F("QUIT"));

  while(!client.available()) {
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 10000) {
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return;
    }
  }

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  client.stop();

  Serial.println(F("disconnected"));
}
String StringArrayString(String arr[])
{
  String retStr = "";
    for (int i = 0; i < 24; i++)
      {
        retStr += arr[i] + "\n";
        //Serial.println(arr[i]);
      }
  return retStr;
}
void SaveData(){
        LeftFloatTemp[x] = LeftTempCel;
        RightFloatTemp[x] = RightTempCel;
        sprintf(MessageBodyValue, "%02d:%02d:%02d", hour(), minute(), second() );
        Time[x] = String(MessageBodyValue);
        //Serial.println(Time[x] + " " + sec5 + " " + interval + " " + x);
        Serial.println(String(LeftFloatTemp[x]));
 }

If anyone can see a better way of executing this I will most likely be taking advice I just don’t understand how.

This line of code that is commented out, it works. It actually allows my code to run but when I get the e-mail it sends me a blank message.

 // MessageBodyTotal[i] =( "Current time is: "); + Time[i] + " Left Temp : " + String(LeftFloatTemp[i]) + " Right Temp: " + String(RightFloatTemp[i]));