Converting String Class to C string, parsing client

I’m having a problem converting a program which used String class (in order to eliminate the overhead) but I cannot see my error:

Working Code using String class:

void webControl()
{
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        if (readString.length() < 100) 
        {
          readString += c;
          DEBUG_PRINTLN(c);
        }
        if (c == '\n') //if HTTP request has ended
        {
          DEBUG_PRINTLN(readString);
          client.println(F("HTTP/1.1 200 OK")); //new page
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<meta name='apple-mobile-web-app-capable' content='yes' />"));
          client.println(F("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"));
          client.println(F("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />"));
          client.println(F("<TITLE>Jim's Home Automation</TITLE>"));
          client.println(F("</HEAD>"));
          client.println(F("<BODY>"));
          client.println(F("<H1>NTP Clock Light</H1>"));
          client.println(F("<hr />"));
          client.println(F("
"));
          client.println(F("<a href=\"/?lighton\"\">Turn On Light</a>"));
          client.println(F("<a href=\"/?lightoff\"\">Turn Off Light</a>
"));  
          client.println(F("
"));
          client.println(F("
"));
          client.println(F("<a href=\"/?syncClock\"\">Synchronize Clock</a>")); 
          client.println(F("</BODY>"));
          client.println(F("</HTML>"));
          delay(1);
          client.stop();
          if(readString.indexOf("?lighton") > 0) // control arduino pin and LCD backlight //checks for 'on'
          {
            digitalWrite(LED_PIN, HIGH);
            lcd.backlight();
            DEBUG_PRINTLN(F("Led On"));
          }
          else if (readString.indexOf("?lightoff") > 0)//checks for 'off'
          {
            digitalWrite(LED_PIN, LOW);
            lcd.noBacklight();
            DEBUG_PRINTLN(F("Led Off"));
          }
          else if (readString.indexOf("?syncClock") > 0)
          {
            forceClockUpdate = true;
          }
          readString=""; //clearing string for next read
        }
      }
    }
  }
}

Broken Code with char array:

void webControl()
{
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        if (sizeof(myString) < 100)
        {
          myString[locator] = c;
          locator++;
          Serial.println(myString);
        }
        if (c == '\n') //if HTTP request has ended
        {
          DEBUG_PRINTLN(F("MyString ="));
          DEBUG_PRINTLN(myString);
          client.println(F("HTTP/1.1 200 OK")); //new page
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<meta name='apple-mobile-web-app-capable' content='yes' />"));
          client.println(F("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"));
          client.println(F("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />"));
          client.println(F("<TITLE>Jim's Home Automation</TITLE>"));
          client.println(F("</HEAD>"));
          client.println(F("<BODY>"));
          client.println(F("<H1>NTP Clock Light</H1>"));
          client.println(F("<hr />"));
          client.println(F("
"));
          client.println(F("<a href=\"/?lighton\"\">Turn On Light</a>"));
          client.println(F("<a href=\"/?lightoff\"\">Turn Off Light</a>
"));  
          client.println(F("
"));
          client.println(F("
"));
          client.println(F("<a href=\"/?syncClock\"\">Synchronize Clock</a>")); 
          client.println(F("</BODY>"));
          client.println(F("</HTML>"));
          delay(1);
          client.stop();
          char * ptr1;
          ptr1 = strstr(myString, "?lighton");
          if(!ptr1) // control arduino pin and LCD backlight //checks for 'on'
          {
            digitalWrite(LED_PIN, HIGH);
            lcd.backlight();
            DEBUG_PRINTLN(F("Led On"));
          }
          ptr1 = strstr(myString, "?lightoff");
          if (!ptr1)//checks for 'off'
          {
            digitalWrite(LED_PIN, LOW);
            lcd.noBacklight();
            DEBUG_PRINTLN(F("Led Off"));
          }
          ptr1 = strstr(myString, "?syncClock");
          if (!ptr1)
          {
            forceClockUpdate = true;
            DEBUG_PRINTLN(F("Sync Set"));
          }
          myString[0] = '\0'; //clearing string for next read
          locator = 0;
        }
      }
    }
  }
}

outputs:

configuring ethernet
Time:12:00:04 am Thursday
Seconds since Jan 1 1900 = 3626655788
Unix time = 1417666988
Time value received: Clock updated…
Sensor’s time currently set to: 11:23pm
12/3/2014
Wednesday
Time:11:23:10 pm Wednesday
Time:11:23:11 pm Wednesday
Time:11:23:12 pm Wednesday
Time:11:23:13 pm Wednesday
MyString = <<<<<Edit Pushed the web link here… empty string

Led On <<<<< all three options selected… I inverted the pointer!
Led Off
Sync Set
Time:11:23:14 pm Wednesday
Seconds since Jan 1 1900 = 3626655793
Unix time = 1417666993
Time value received: Time:11:23:15 pm Wednesday
Time:11:23:16 pm Wednesday
Time:11:23:17 pm Wednesday
Time:11:23:18 pm Wednesday
Time:11:23:19 pm Wednesday
Time:11:23:20 pm Wednesday
Time:11:23:21 pm Wednesday
Time:11:23:22 pm Wednesday
Time:11:23:23 pm Wednesday
Time:11:23:24 pm Wednesday
Time:11:23:25 pm Wednesday
Time:11:23:26 pm Wednesday

entire working code attached…

NTPClockWithWebPage.ino (8.12 KB)

not working code here:

#include <Wire.h>
#include <SPI.h>         
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SD.h>
#include <Time.h>
#include <Timezone.h>
#include <LiquidCrystal_I2C.h>


#define DEBUG_ON
#define LED_PIN 8

#ifdef DEBUG_ON
#define DEBUG_PRINT(x)   Serial.print(x)
#define DEBUG_PRINTLN(x) Serial.println(x)
#define SERIAL_START(x)  Serial.begin(x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#define SERIAL_START(x)
#endif
//
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint8_t clock[8] = {
  0x0,0xe,0x15,0x17,0x11,0xe,0x0}; // I'm-fetching-time indicator
//
EthernetUDP Udp;
EthernetServer server(80);
byte mac[] = { 
  0xDE, 0xDE, 0xDE, 0xDE, 0xDE, 0xDE };
unsigned int localPort = 8888;
IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server  // IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov NTP server  // IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov NTP server
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 
//
const char *dayOfWeek[] = {
  "Null","Sunday ","Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "};
// 
TimeChangeRule usEDT = {
  "EDT", Second, Sun, Mar, 2, -240};  //Eastern Daylight Time = UTC - 4 hours
TimeChangeRule usEST = {
  "EST", First, Sun, Nov, 2, -300};   //Eastern Standard Time = UTC - 5 hours
Timezone usET(usEDT, usEST);
TimeChangeRule *tcr;
//
boolean justStarted = true;
boolean forceClockUpdate = true;
//
float humidity, temperature;
//
char myString[100];
byte locator = 0;
//
//
void setup() 
{
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
  DEBUG_PRINTLN(F("configuring ethernet"));
  if (Ethernet.begin(mac) == 0) // start Ethernet and UDP
  {
    DEBUG_PRINTLN(F("Failed to configure Ethernet using DHCP")); 
    while(true){
    }
  }
  server.begin();
  Udp.begin(localPort);
  //
  lcd.init();
  lcd.clear();
  lcd.backlight();
  lcd.createChar(0, clock);
  lcd.print("   NPT  Clock   ");
  delay(3000);
}
//
void loop()
{
  updateLCD();
  getNTPtime();
  webControl();
}
//
void updateLCD()
{
  static int lastSecond; 
  time_t rightNow = now();
  if (second(rightNow) != lastSecond)
  {
    lcd.setCursor(0,0);
    lcd.print(F("Time:"));
    DEBUG_PRINT(F("Time:"));
    lcd.print(hourFormat12(rightNow) < 10 ? F(" ") : F(""));
    DEBUG_PRINT(hourFormat12(rightNow) < 10 ? F(" ") : F(""));
    lcd.print(hourFormat12(rightNow));
    DEBUG_PRINT(hourFormat12(rightNow));
    lcd.print(minute(rightNow) < 10 ? F(":0") : F(":"));
    DEBUG_PRINT(minute(rightNow) < 10 ? F(":0") : F(":"));
    lcd.print(minute(rightNow));
    DEBUG_PRINT(minute(rightNow));
    lcd.print(second(rightNow) < 10 ? F(":0") : F(":"));
    DEBUG_PRINT(second(rightNow) < 10 ? F(":0") : F(":"));
    lcd.print(second(rightNow));
    DEBUG_PRINT(second(rightNow));
    lcd.print(isAM() ? "am" : "pm");
    DEBUG_PRINT(isAM() ? " am " : " pm ");
    lcd.setCursor(0,1);
    lcd.print(dayOfWeek[weekday(rightNow)]);
    DEBUG_PRINTLN(dayOfWeek[weekday(rightNow)]);
    lcd.print(F("      "));
    lcd.setCursor(11,1);
    lcd.print(month(rightNow) < 10 ? F(" ") : F(""));
    lcd.print(month(rightNow));
    lcd.print(day(rightNow) < 10 ? F("/0") : F("/"));
    lcd.print(day(rightNow));
  }
  lastSecond = second(rightNow);
}
//unsigned long
void sendNTPpacket(IPAddress& address) // Send an NTP request to the time server at the given address 
{
  memset(packetBuffer, 0, NTP_PACKET_SIZE); 
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;            // Stratum, or type of clock
  packetBuffer[2] = 6;            // Polling Interval
  packetBuffer[3] = 0xEC;         // Peer Clock Precision
  packetBuffer[12]  = 49; 
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;		   
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket(); 
}
//
void receiveTime(unsigned long newTime)
{
  DEBUG_PRINT(F("Time value received: "));
  int lastSecond = second();
  int lastMinute = minute();
  int lastHour = hour();
  setTime(newTime);
  if ((second() != lastSecond) || (minute() != lastMinute) || (hour() != lastHour))
  {
    DEBUG_PRINTLN(F("Clock updated...."));
    DEBUG_PRINT(F("Sensor's time currently set to:"));
    DEBUG_PRINT(hourFormat12() < 10? F(" 0") : F(" "));
    DEBUG_PRINT(hourFormat12());
    DEBUG_PRINT(minute() < 10? F(":0") : F(":"));
    DEBUG_PRINT(minute());
    DEBUG_PRINTLN(isAM()? F("am") : F("pm"));
    DEBUG_PRINT(month());
    DEBUG_PRINT(F("/"));
    DEBUG_PRINT(day());
    DEBUG_PRINT(F("/"));
    DEBUG_PRINTLN(year());
    DEBUG_PRINTLN(dayOfWeek[weekday()]);
  }
  lcd.setCursor(15,0);
  lcd.print(F(" "));
}
//
void getNTPtime()
{
  static unsigned long lastUpdateTime;
  const unsigned long interval = 600000UL;
  if ((millis() - lastUpdateTime >= interval) || forceClockUpdate)
  {
    lcd.setCursor(15,0);
    lcd.write(0);
    sendNTPpacket(timeServer); // send an NTP packet to a time server
    delay(1000);  
    if (Udp.parsePacket()) 
    {  
      Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer
      unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
      unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);  
      unsigned long secsSince1900 = highWord << 16 | lowWord;  
      DEBUG_PRINT(F("Seconds since Jan 1 1900 = "));
      DEBUG_PRINTLN(secsSince1900);               
      Serial.print(F("Unix time = "));
      time_t utcEpoch = secsSince1900 - 2208988800UL;//seventyYears = 2208988800UL
      DEBUG_PRINTLN(utcEpoch);                               
      receiveTime(usET.toLocal(utcEpoch, &tcr) + 2);  //about 2 seconds to call for time
    }
    if (!forceClockUpdate)
    {
      lastUpdateTime += interval;
    }
    forceClockUpdate = false;
  }
}
//
void webControl()
{
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        if (sizeof(myString) < 100)
        {
          myString[locator] = c;
          locator++;
          Serial.println(myString);
        }
        if (c == '\n') //if HTTP request has ended
        {
          DEBUG_PRINTLN(F("MyString ="));
          DEBUG_PRINTLN(myString);
          client.println(F("HTTP/1.1 200 OK")); //new page
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<meta name='apple-mobile-web-app-capable' content='yes' />"));
          client.println(F("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"));
          client.println(F("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />"));
          client.println(F("<TITLE>Jim's Home Automation</TITLE>"));
          client.println(F("</HEAD>"));
          client.println(F("<BODY>"));
          client.println(F("<H1>NTP Clock Light</H1>"));
          client.println(F("<hr />"));
          client.println(F("
"));
          client.println(F("<a href=\"/?lighton\"\">Turn On Light</a>"));
          client.println(F("<a href=\"/?lightoff\"\">Turn Off Light</a>
"));  
          client.println(F("
"));
          client.println(F("
"));
          client.println(F("<a href=\"/?syncClock\"\">Synchronize Clock</a>")); 
          client.println(F("</BODY>"));
          client.println(F("</HTML>"));
          delay(1);
          client.stop();
          char * ptr1;
          ptr1 = strstr(myString, "?lighton");
          if(!ptr1) // control arduino pin and LCD backlight //checks for 'on'
          {
            digitalWrite(LED_PIN, HIGH);
            lcd.backlight();
            DEBUG_PRINTLN(F("Led On"));
          }
          ptr1 = strstr(myString, "?lightoff");
          if (!ptr1)//checks for 'off'
          {
            digitalWrite(LED_PIN, LOW);
            lcd.noBacklight();
            DEBUG_PRINTLN(F("Led Off"));
          }
          ptr1 = strstr(myString, "?syncClock");
          if (!ptr1)
          {
            forceClockUpdate = true;
            DEBUG_PRINTLN(F("Sync Set"));
          }
          myString[0] = '\0'; //clearing string for next read
          locator = 0;
        }
      }
    }
  }
}

I figured it out… cannot use sizeof(charArray)…

working new code, no String Class…

saved 2000bytes!

void webControl()
{
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        if (locator < 100)
        {
          myString[locator] = c;
          locator++;
          myString[locator] = '\0'; 
        }
        if (c == '\n') //if HTTP request has ended
        {
          DEBUG_PRINTLN(F("MyString ="));
          DEBUG_PRINTLN(myString);
          client.println(F("HTTP/1.1 200 OK")); //new page
          client.println(F("Content-Type: text/html"));
          client.println();
          client.println(F("<HTML>"));
          client.println(F("<HEAD>"));
          client.println(F("<meta name='apple-mobile-web-app-capable' content='yes' />"));
          client.println(F("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />"));
          client.println(F("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />"));
          client.println(F("<TITLE>Jim's Home Automation</TITLE>"));
          client.println(F("</HEAD>"));
          client.println(F("<BODY>"));
          client.println(F("<H1>NTP Clock Light</H1>"));
          client.println(F("<hr />"));
          client.println(F("
"));
          client.println(F("<a href=\"/?lighton\"\">Turn On Light</a>"));
          client.println(F("<a href=\"/?lightoff\"\">Turn Off Light</a>
"));  
          client.println(F("
"));
          client.println(F("
"));
          client.println(F("<a href=\"/?syncClock\"\">Synchronize Clock</a>")); 
          client.println(F("</BODY>"));
          client.println(F("</HTML>"));
          delay(1);
          client.stop();
          char * ptr1;
          ptr1 = strstr(myString, "?lighton");
          if(ptr1) // control arduino pin and LCD backlight //checks for 'on'
          {
            digitalWrite(LED_PIN, HIGH);
            lcd.backlight();
            DEBUG_PRINTLN(F("Led On"));
          }
          ptr1 = strstr(myString, "?lightoff");
          if (ptr1)//checks for 'off'
          {
            digitalWrite(LED_PIN, LOW);
            lcd.noBacklight();
            DEBUG_PRINTLN(F("Led Off"));
          }
          ptr1 = strstr(myString, "?syncClock");
          if (ptr1)
          {
            forceClockUpdate = true;
            DEBUG_PRINTLN(F("Sync Set"));
          }
          myString[0] = '\0'; //clearing string for next read
          locator = 0;
        }
      }
    }
  }
}