473,473 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

abbreviate string

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
2 3173
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
2
by: voidmaingetch | last post by:
hey i was asking, y'know, how do i abbreviate a string. eg--if i give>> world health organization it'll give me<< w.h.o.
10
by: Chris H | last post by:
Greetings, I'm trying to update an address field with "standard" abbreviations so that I can do a comparison of various accounts to one another on the address. I can update a set of records for...
7
by: Sunny | last post by:
Hi, Is there a way in Javascript to abbreviate currency. Like if it is $1000 then it convert it into 1K.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.