Split and send a string one character at a time

I want to know how to split a variable up into it's individual parts.
The variable can be between 4 and 6 characters long, and is alphanumeric.


void processData()

char pass = "12345A";

<some code here to determine length of string>

<length = "number of characters"; >

<for loop? to iterate through each character (using length variable) and send to function printpass()  >

void printpass()



Any hints on how to do this?

You need to define your string in an array of chars

char pass [] = "12345A";

Then you can use several functions related to strings

As an example:

char pass [] = "12345A";

void setup() {
  int len = strlen(pass);
  for (int i=0;i<len;i++) Serial.println(pass[i]);

void loop() {

This displays:


@lesept thanks that is what I was trying to formulate!

Thanks for the link too, I was just looking on the Arduino pages and reading about strings, lots of useful functions: https://www.arduino.cc/en/Tutorial/BuiltInExamples#strings


That link takes you to a page about Strings (objects created using the String library). lesept used strings (arrays of chars terminated by a zero)

The former are not well regarded in the small memory footprint of the average Arduino and should be used with caution, if at all, whilst the latter are not memory hogs and are preferred

Thanks UKHeliBob, I was wondering about that. As I read that strings are not preferred for Arduino as they can cause memory issues.

That clears it up :wink:

Be careful with your use of the words string and String

strings (lowercase s) are to be preferred in the Arduino small memory environment

Hmm having an daft issue here.

As I'm using BLYNK_WRITE it only support Strings

String pass = param.asStr();

So I of course need convert it to a character array. I could use for example "pass.toCharArray(button, 10)”
but it seems to need the array length setting, which I don't want.

Maybe I could use something like:

// assigning value to string s 

    string s = "geeksforgeeks"; 


    int n = s.length(); 


    // declaring character array 

    char char_array[n + 1]; 


    // copying the contents of the 

    // string to char array 

    strcpy(char_array, s.c_str());

I just wonder if there’s a better way?

As I'm using BLYNK_WRITE it only support Strings

According to: Documentation for Blynk, the most popular IoT platform for businesses. it supports:


You could also try:

char *buff = (char *) param.getBuffer();

This should give you a pointer to the raw character buffer which should be a null-terminated c-string.

Nice! I didn't see those other options of buffer/length.

char *buff = (char *) param.getBuffer();

This works for me, I'm not 100% sure how it works?