character arrays behaving erratic

Hi all

I am at a complete loss. I have pasted the code in below but cannot figure out why the character arrays are not storing values.

char cAT1[6];
char cAT2[6];
while ((strcmp(cAT1,“AT+CCL”) != 0) || (strcmp(cAT2,“CCLK:”) != 0)){
sBuffer = time_request();
Serial.println(sBuffer);

for (int i = 0; i <= 6; i++){
cAT1 = sBuffer*; // there is a website bug here, this line should have a i between brackets after sBuffer*
* if (i == 6) cAT1[6] = ‘\0’;*
* }*

* Serial.print("AT1 = ");*
* Serial.println(cAT1);*
* Serial.print("AT2 = ");*
* Serial.println(cAT2);*

* for (int i = 0; i <= 6; i++){*
_ cAT2 = sBuffer[i+11];
* if (i == 6) cAT2[6] = ‘\0’;
}*_

* Serial.print("AT1 = ");*
* Serial.println(cAT1);*
* Serial.print("AT2 = ");*
* Serial.println(cAT2);*
* Serial.println(“End--------------------”);*
* }*
Now the response that I get is the following:
AT+CCLK?
+CCLK: “04/01/01,00:17:25+08”
OK
AT1 = AT+CCL
AT2 =
AT1 =
AT2 = +CCLK:
End--------------------
As you can see, for some unknown reason, AT1 is rewritten after i run the second for loop.
Any help would be massively appreciated.

Misha7171:
Any help would be massively appreciated.

Posting complete code that actually compiles and doing so using CODE TAGS would be massively appreciated.

See Item #6 here: Read this before posting a programming question .... The title says it all.

char cAT1[6];
char cAT2[6];
while ((strcmp(cAT1,"AT+CCL") != 0) || (strcmp(cAT2,"CCLK:") != 0))

A 6 element array can NOT hold AT+CCL and a terminating NULL.

   for (int i = 0; i <= 6; i++){
        cAT2[i] = sBuffer[i+11];
        if (i == 6) cAT2[6] = '\0';
    }

A 6 element array does NOT have a position 6.

When you sh*t on memory you don’t own, you can NOT expect rational behavior from a program.

Posting complete code that actually compiles and doing so using CODE TAGS would be massively appreciated.

On the other hand, the problem was quite obvious from the code that was (poorly) posted.