Use char arrays instead strings

I have made sketch with arduino uno and esp8266 in which i send measures of HC-SR04 to a website. I want to convert the code so I can use char arrays instead strings. How can I do this? Can someone help me with a few lines of code? My code is:

#include <SoftwareSerial.h>
SoftwareSerial espSerial =  SoftwareSerial(2,3);  

//Wifi network SSID password
String ssid="ffffff";
String password ="*******";

boolean DEBUG=true;

int echoPin = 12; 
int trigPin = 13; 

long duration, distance; 
int alarm;

String alarms;

String data;
String server = "www.example.com"; // Send data to this site

String uri = "/add2.php";

int error = 0;
int cancel = 0;

void showResponse(int waitTime){
    long t=millis();
    char c;
    while (t+waitTime>millis()){
      if (espSerial.available()){
        c=espSerial.read();
        if (DEBUG) Serial.print(c);
      }
    }
                   
}

boolean websiteWrite(long value1, int value2){ 
  if (value2 == 0){
    alarms = "OFF";
  }else{
    alarms = "ON";
  }
  
  data = "distance=" + String(value1) + "&alarm=" + alarms;
  
  espSerial.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
  
  if( espSerial.find("OK")) {
  
  Serial.println("TCP connection ready"); cancel = 0;
  
  }
  else{
    cancel = cancel + 1;  Serial.println("cancel="); Serial.println(cancel);
  }
  delay(1000);
  
  String postRequest =
  
  "POST " + uri + " HTTP/1.0\r\n" +
  
  "Host: " + server + "\r\n" +
  
  "Accept: *" + "/" + "*\r\n" +
  
  "Content-Length: " + data.length() + "\r\n" +
  
  "Content-Type: application/x-www-form-urlencoded\r\n" +
  
  "\r\n" + data;
  
  String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
  
  espSerial.print(sendCmd);
  
  espSerial.println(postRequest.length() );
  
  delay(500);
  
  if(espSerial.find(">")) { Serial.println("Sending.."); espSerial.print(postRequest);
  
  if( espSerial.find("SEND OK")) { Serial.println("Packet sent");
  
  while (espSerial.available()) {
  
  String tmpResp = espSerial.readString();
  
  Serial.println(tmpResp);
  
  }
  
  // close the connection
  
  espSerial.println("AT+CIPCLOSE");
  
  }
    error = 0;
  }else{
    error = error + 1;
    Serial.println("error=");
    Serial.println(error);
    
  }
  
  if(cancel >=15 || error >= 15){software_Reset() ;}
  
}

void setup() {
  delay(150000); 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  
  DEBUG=true;           
  Serial.begin(9600); 
  
  espSerial.begin(9600);  
  
  //espSerial.println("AT+RST");         
  //showResponse(1000);
  
  //espSerial.println("AT+UART_DEF=9600,8,1,0,0");    
  //showResponse(1000);
  
  espSerial.println("AT+CWMODE=1");   
  showResponse(1000);

  espSerial.println("AT+CWJAP=\""+ssid+"\",\""+password+"\"");  
  showResponse(5000);

  if (DEBUG)  Serial.println("Setup completed");  
}

void loop() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;
  
  if (distance<=8){
    alarm=1;
  }else{
    alarm=0;
  }
  
      if (isnan(distance)) {
        if (DEBUG) Serial.println("Failed of calculation the distance");
      }
      else {
          if (DEBUG)  Serial.println("Distance="+String(distance)+" cm");
           websiteWrite(distance,alarm);                                      // Write values to website
      }
  
    
  //Needs 60 sec delay between updates    
  delay(60000);    
}

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile ("  jmp 0");  
}

An example of building an HTML string

void handleRoot()
{
  snprintf(HTMLbuffer, HTMLbufferSize, "<!DOCTYPE html>\
<html>\
<head>\
<style>\
.colourSquare {width: 300px; height: 300px; font-size: 80px; color: WHITE; font-weight:bold; display: inline-block;}\
</style>\
</head>\
<form action=\"/redLED\" method=\"POST\"><input type=\"submit\" class=\"colourSquare\" style=\"background-color:RED;\" value=\"%s\"></form>\
<form action=\"/greenLED\" method=\"POST\"><input type=\"submit\" class=\"colourSquare\" style=\"background-color:GREEN;\" value=\"%s\"></form>\
<form action=\"/blueLED\" method=\"POST\"><input type=\"submit\" class=\"colourSquare\" style=\"background-color:BLUE;\" value=\"%s\"></form>\
</html>", redText, greenText, blueText);
  server.send(200, "text/html", HTMLbuffer );
  Serial.print("leaving handleRoot\t");
  Serial.println(millis());
  Serial.println();
  showHTMLbuffer();
}

This example builds the HTML and inserts the values for red, green and blue text previously set in another part of the program.

The primary difference is that char arrays that are treated as strings by appending a null character, '\0', at the end of the characters that comprise the array. The null character serves as a sentinel to mark the end of the string. The string name serves as the start of the string. For example:

   char passWord[10];

   strcpy(passWord, "secret");

Note that because passWord[] is defined as having 10 elements, the max length of passWord[] is 9 characters, because there must be room for the null. Also note in the string copy function, the first argument is passWord with no brackets. This illustrates that passWord by itself (i.e., no brackets) is viewed by the compiler as &password[0], or the starting memory address of the string array of chars. Most of the string processing functions are of the form shown here:

_ str*(destinationString, sourceString);_

Unlike the String class (note the uppercase 'S'), manipulation of string data (note lower case 's') is done via library functions rather than by operators. You can find a summary of the mem*() and str*() string processing functions here. As a general rule, the mem*() functions have less error checking code associated with them (e.g., overlaps, lengths, etc.) so they are often marginally faster than their str*() counterparts.

The evils of Strings page tells why we don't like to use Strings and how to use some string functions in their place.