abbreviate string

Discussion in 'C Programming' started by maurir, Oct 25, 2005.

  1. maurir

    maurir Guest

    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.
     
    maurir, Oct 25, 2005
    #1
    1. Advertising

  2. 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
     
    Peter Nilsson, Oct 25, 2005
    #2
    1. Advertising

  3. maurir

    Eric Sosman Guest

    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
     
    Eric Sosman, Oct 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    0
    Views:
    738
    Mladen Adamovic
    Dec 4, 2003
  2. Mladen Adamovic
    Replies:
    3
    Views:
    14,611
    Mladen Adamovic
    Dec 5, 2003
  3. Matt
    Replies:
    3
    Views:
    507
    Tor Iver Wilhelmsen
    Sep 17, 2004
  4. Replies:
    9
    Views:
    324
    Thomas J. Gritzan
    Nov 25, 2005
  5. Sunny

    Abbreviate Currency using Javascript

    Sunny, Sep 26, 2008, in forum: Javascript
    Replies:
    5
    Views:
    158
    Dr J R Stockton
    Sep 27, 2008
Loading...

Share This Page