Finding a Specific Char In Array

For example, if I have an array thats

char password[5]="3","4","*", "5";

How do you say, search through it and give the index value of the *

In addition, how do you also replace the star with a random number.

So, when I call the function, it searches the password array for a star, then if there is, replaces it with a random number.

I'm pretty new to the Arduino and sorry if it's a newbie question. Thanks in advance!

Did you mean this?char password[5]={'3', '4', '*', '5'};

char password[] = "34*5";
 :
password[ strchr(password, '*') ] = '0' + random(10)

strchr() is a standard C function; I don't know whether it'll appear in the Arduino documentation.

you can do something like this:

int search_and_destroy(char *buff, size_t len, char c)
{
   for (int i=0; i<len; i++) {
      if (buff[i] == c) {
         return i;
      }
   }
   return -1;
}

The function expects a buffer, its length, and the char to search for.
It returns the index of the char or -1.

It returns the index of the char or -1.

Much like strchr(), mentioned in the previous post.

jremington:
Much like strchr(), mentioned in the previous post.

Isn't that strchr() return a char pointer? you can use arithmetic on that pointer but I think you still need to do extra checking for it to work.

arduino_new:
Isn't that strchr() return a char pointer? you can use arithmetic on that pointer but I think you still need to do extra checking for it to work.

But it is bright enough to work out for itself how long the string is.

AWOL:
But it is bright enough to work out for itself how long the string is.

original post had an array of char instead of a cstring.
I was under the impression that he had an array of char instead of a cstring. But he had neither.

Isn't that strchr() return a char pointer

oops. You're right.

char password[] = "34*5";
 :
*( strchr(password, '*') ) = '0' + random(10);

Or

char password[] = "34*5";
 :
strchr(password, '*')[0] = '0' + random(10);

(tried them out this time. they work.)
(As long as you're REALLY SURE that the string contains a '', you don't need extra checking. But Bad Things Might Happen if there is no '' and you later count on having the null termination there...)