char buf[100] = {0}; // this is an array
char inChar;
bool stringComplete = false;
int i = 0;
// declare the function
char ConvertString(char);
void setup()
{
// Initialize serial and wait for port to open
Serial.begin(115200);
while (!Serial)
{
// Wait for serial port to connect, needed for native USB port only
}
}
void loop()
{
while (Serial.available())
{
inChar = (char)Serial.read();
if (inChar == '\n') // change '\n' to '~' when using Tinkercad
{
buf[i++] = inChar; // last character is newline
buf[i] = 0; // string array should be terminated with a zero
stringComplete = true;
}
else
{
buf[i++] = inChar;
}
}
if (stringComplete)
{
Serial.print(buf); // the printing of string will be stopped when zero is reached
stringComplete = false;
i = 0;
}
}