Q. Write a function Stars() whose input are an array of characters(a), the size of the array(n), and a character(ch). This function should replace all occurrences of ch in the array, a, with a star(*), and return the number of times the replacement was made.

So far I have the function prototype

int stars(char a[n], char ch, int n)
{
}

In other words, you have nothing. Give it a try first, then we'll be more inclined to help you.

does this look ok?

int stars(char a[n], char ch, int n)
{
  int replacenum = 0;
  int i;

  for ( i = 0; i < replacenum; i++)
  {
    if (a[i] == ch)
    {
      a[i] = '*';
    }
  }
  replacenum = a[n];

  return replacenum;
}

>does this look ok?
No, it doesn't. Did you compile and run it before asking that?

I did now and it doesn't work. I'll figure it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.