Script to swap a character for an asterisk in a string

Asked

Viewed 1,040 times

-1

Hello! I need to make a program that reads a text (string) typed by the user with a maximum of 500 characters, and print this text by replacing the first letter of each word with an asterisk '*'.

Can someone help me?

  • 1

    Hello Viviana, can you not put the code you have produced so far and we will guide you so that you build the program and learn from it, which I imagine is the goal of this right program of yours?

  • 1

    This should be done with language C or C++?

  • @Viviana, this question seems to be duplicated, two times ago I answered one with this same objective. a look:http://answall.com/questions/88015/comort-testar-a-condi%C3%A7%C3%A3o-em-um-vetor

  • Thank you very much, Gabriel!! That’s just what I needed! I had not seen that this question had already been asked.

  • He’s in the same class ;)

1 answer

1

Assuming you’re using C

void subs(char *str)
{
   str[0] = '*';
   int size = strlen(str);
   for(int i = 1; i < size; i++)
      if(str[i - 1] == ' ')
         str[i] = '*'
}

// Dentro da main vc le normal e chama a funcao
subs(string);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.