WIFI.begin(ssid,pw) only works half the time with same arguments

So I am attempting to connect my ESP32 to WIFI with credentials provided over Bluetooth.

I successfully sendthe ssid and pw over Bluetooth to the ESP32.

I convert it to a const char*, which is the data type that the WIFI.begin() requires.

i convert it as such:

You have to post the complete program for an answer.
However, I guess the const char* type definition is appropriate only if the credentials are embedded in the program and, therefore, known at compile time.

I also have the same problem with my ESP8266 board no matter the different types of code I do. Sometimes however, it does work so I am not to sure of a fix hardware or software wise

Shows us the program and we can have a look, rarely it will be a hardware issue, If the credentials are in a char array (buffer) it is not required for them to be known at compile time.