maurir wrote:
Hello
I have an array of char, like these examples:
John Smith
Juan de la Rosa
Darren Russel Miller
Ana Maria da Silva Santos
The output of the compacted string's image:
John Smith
Juan de la Rosa
Darren R. Miller
Ana M. da S. Santos
So, the program has to abbreviate the middle names or surnames
when they exist. If not, the string is reproduced. I have to modify
the original string and not create a copy of it. Any ideas of how to
start?
Your question appears to be about an algorithm, not C specifically.
Since you haven't posted an attempt (good or bad) at either, you're not
likely to persuade many people on usenet to help you.
But to start with, use two pointers: one for reading the source, the
other for writing. They can both point to the same array. Since you're
only ever shortening the string, it should be a simple matter of just
iterating through the characters of the original string. [Watch out of
single letter names though.]
--
Peter