Arduino Wifi Works one way but not the other? (ESP32) (Possible Variable Type Problem) I am working on a code that accepts input from serial monitor and connects to Wifi, and have been getting issues.

my SSID for my wifi is "SamF" but for some reason arduino only likes it when I initialize at the top, not when I accept it from serial monitor even though they are the same..

Example The below code works:

#include &lt;WiFi.h&gt;

char ssid[] = "SamF"; //OR const char* = "SamF"
char pass[] = "secretPassword";
void setup()
{
WiFi.begin(ssid, pass);
}
void loop () {}


The Code Below Does not work..

#include &lt;WiFi.h&gt;
char pass[] = "secretPassword";
void setup()
{
ssidSerial = my code that receives Serial input and converts to char

for(int k=0;k&lt;=3;k++){
ssidPlaceHolder[k]=ssidSerial[k];
}
const char* ssid = ssidPlaceHolder;
WiFi.begin(ssid, pass);
}
void loop () {}


Everything compiles fine, I debugged by using Serial.print and they are both displaying "SamF" and sizeof(ssid) for both is 4... so I am not sure why one works and the other doesn't? any ideas?

Thanks in advance for any help, and if anyone needs the code after I am done I will be more than glad to share it on git!
Basic string in C is an array of characters terminated by a 0. All functions taking char* or const char* use this 0 to determine the end of the string, because there is no other information about the length of that string.

In your question you copy characters from one characters buffer to other, but you do not set the terminating 0, so the function begin takes the data after the pass pointer until some random memory location with 0.