Can I make a char pointer point to each position of a char vector in the C language?

Asked

Viewed 62 times

0

ex: suppose a string called "Gustavo". How I make a pointer point to each position of the string and go applying the following rule.

  1. If the pointer finds the vowel A, the contents of that pointer shall receive "AUAU"
  2. If the pointer meets the vowel U, the contents of that pointer shall receive "AUAUAUAUAU"

at the end the contents of the pointer thus: Gauauauauaustauauauauvo

NOTE: I don’t want to modify the original string but use it as a basis for can apply the above rules by storing them in the contents of my pointer.

  • I believe that you cannot point to the resulting string with this pointer without using an auxiliary variable, unless you were changing the string itself that is being checked. But it would be good for you to show what you’ve tried.

  • 1

    To do such a substitution you have to copy to the resulting string or each read character that does not need to be replaced or the substitute string. You will have to allocate memory to the resulting string. What you can do is reallocate each character(s) to the string.

  • https://ideone.com/r4V9ro

No answers

Browser other questions tagged

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