I'm trying to understand WiFiNINA library's WiFiWebServer example

I'm trying to understand WiFiWebServer.ino included in File | Examples | WiFiNINA Library version 1.3.0

I wanted to print my own string to the browser, so I did this.

char mySting[1] = {' '}; // at top of sketch, there is a space between Single quotes.

and this

client.print(mySting); I added this line, and declaration above to otherwise original sketch

When I run it, it displays my SECRET PASSWORD to browser.

This doesn't seem right!

HELP, Thanks

myString is a char array with a single element. When you call print() with a char array, it expects a null-terminated char array, and will continue printing whatever is stored in memory after your array until it encounters a null. In this case that just happens to be your password. If you declare myString as a char instead of a char array, then the print() should work correctly.

What you wrote:

char mySting[1] = {' '};  // A character array containing a single character

What would work:

char mySting = {' '};  // A character
char mySting[] = " "; // A character array containing a null terminated string
const char *mySting = " ";  // A pointer to a null terminated string

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.