abbreviate string

M

maurir

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.
 
P

Peter Nilsson

maurir said:
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.]
 
E

Eric Sosman

maurir said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top