By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

abbreviate string

P: n/a
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?
Thanks in advance.

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Nov 15 '05 #2

P: n/a
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?
Thanks in advance.


As Peter Nilsson observes, the question is more about
algorithms than about C. Personally, I think it will be
difficult to concoct a suitable algorithm because of the
cultural context of names. For example, it would certainly
be wrong to output "Alexander T. Great" or "Baron V. Steuben"
or "Charles P. A. G. Windsor," and "Aragorn S. O. Arathorn"
doesn't even bear imagining.

--
Eric Sosman
es*****@acm.org

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.