comp.lang.ada
 help / color / mirror / Atom feed
* How to delete charcters in a string?
@ 2002-01-30  0:25 Anthony Wise
  2002-01-30  2:44 ` Steve Doiel
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Anthony Wise @ 2002-01-30  0:25 UTC (permalink / raw)


hi
(im new to ada by the way)

well supose there is a character in a string which i do not want to be seen 
in the output.  i don't want to change it to anouther character but delete 
it completely.

thx in advance


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
       [not found] <F207EAsx2Pwf500RR1h00019d09@hotmail.com>
@ 2002-01-30  1:16 ` Eric Merritt
  2002-01-30  1:16 ` Eric Merritt
  1 sibling, 0 replies; 19+ messages in thread
From: Eric Merritt @ 2002-01-30  1:16 UTC (permalink / raw)



--- Anthony Wise <iamwisey_@hotmail.com> wrote:
> hi
> (im new to ada by the way)
> 
> well supose there is a character in a string which i
> do not want to be seen 
> in the output.  i don't want to change it to
> anouther character but delete 
> it completely.
> 
> thx in advance
> 
> 
>
_________________________________________________________________
> MSN Photos is the easiest way to share and print
> your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada


__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
       [not found] <F207EAsx2Pwf500RR1h00019d09@hotmail.com>
  2002-01-30  1:16 ` Eric Merritt
@ 2002-01-30  1:16 ` Eric Merritt
  1 sibling, 0 replies; 19+ messages in thread
From: Eric Merritt @ 2002-01-30  1:16 UTC (permalink / raw)


I believe there is a remove subroutine for each string
package - called weirdly enough remove. lol

--- Anthony Wise <iamwisey_@hotmail.com> wrote:
> hi
> (im new to ada by the way)
> 
> well supose there is a character in a string which i
> do not want to be seen 
> in the output.  i don't want to change it to
> anouther character but delete 
> it completely.
> 
> thx in advance
> 
> 
>
_________________________________________________________________
> MSN Photos is the easiest way to share and print
> your photos: 
> http://photos.msn.com/support/worldwide.aspx
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada


__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  0:25 How to delete charcters in a string? Anthony Wise
@ 2002-01-30  2:44 ` Steve Doiel
  2002-01-30  3:22 ` dale
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Steve Doiel @ 2002-01-30  2:44 UTC (permalink / raw)


Since your new to Ada, here's how I find the answer to that question.

First I find the Ada 95 LRM (language reference manual), here's one:

http://www.adaic.org/standards/95lrm/html/RM-TOC.html

Then I look in Annex A which describes the "Predefined Language Environment"
http://www.adaic.org/standards/95lrm/html/RM-A.html and look for something
to do with strings.

Let's see... Ada.Strings.Fixed.  That sounds like it may be what I'm looking
for.... A.43

There I find a function called "Delete" which sounds like what you're
looking for.

Since you're new to Ada I suggest perusing Annex A to see what's available.

SteveD

"Anthony Wise" <iamwisey_@hotmail.com> wrote in message
news:mailman.1012350362.32618.comp.lang.ada@ada.eu.org...
> hi
> (im new to ada by the way)
>
> well supose there is a character in a string which i do not want to be
seen
> in the output.  i don't want to change it to anouther character but delete
> it completely.
>
> thx in advance
>
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  0:25 How to delete charcters in a string? Anthony Wise
  2002-01-30  2:44 ` Steve Doiel
@ 2002-01-30  3:22 ` dale
  2002-01-30  6:37   ` tmoran
  2002-01-30 11:21 ` Preben Randhol
  2002-01-31 14:47 ` Ted Dennison
  3 siblings, 1 reply; 19+ messages in thread
From: dale @ 2002-01-30  3:22 UTC (permalink / raw)


comp.lang.ada@ada.eu.org wrote:

> hi
> (im new to ada by the way)
> 
> well supose there is a character in a string which i do not want to be 
> seen 
> in the output.  i don't want to change it to anouther character but 
> delete 
> it completely.


You can't remove characters from a string. This sounds like a 
limitation, but it is simply asking too much from the "String" type.


Ways around this problem are...

   Construct a brand new string. E.g.

      New_String : String := Old_String (1..4) & Old_String (5..Last);

   You can't however do...

      Old_String := Old_String (1..4) & Old_String (5..Last);



   Use a different type,such as...

      Ada.Strings.Unbounded.Unbounded_String
 

Dale
------------ And now a word from our sponsor ------------------
Do your users want the best web-email gateway? Don't let your
customers drift off to free webmail services install your own
web gateway!
--  See http://netwinsite.com/sponsor/sponsor_webmail.htm  ----



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  3:22 ` dale
@ 2002-01-30  6:37   ` tmoran
  2002-01-30  7:49     ` Dale Stanbrough
  0 siblings, 1 reply; 19+ messages in thread
From: tmoran @ 2002-01-30  6:37 UTC (permalink / raw)


>  You can't however do...
>
>     Old_String := Old_String (1..4) & Old_String (5..Last);
but of course you can do
      Old_String(1 .. Last) := Old_String (1..4) & Old_String (5..Last);

or, if Old_String(Bad_Char_Index) = offensive_character,
  Old_String(Bad_Char_Index .. Last-1) := Old_String(Bad_Char_Index+1 .. Last);
  Last := Last-1;



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  6:37   ` tmoran
@ 2002-01-30  7:49     ` Dale Stanbrough
  2002-01-30 15:04       ` Marin David Condic
  0 siblings, 1 reply; 19+ messages in thread
From: Dale Stanbrough @ 2002-01-30  7:49 UTC (permalink / raw)


tmoran@acm.org wrote:

> >  You can't however do...
> >
> >     Old_String := Old_String (1..4) & Old_String (5..Last);
> but of course you can do
>       Old_String(1 .. Last) := Old_String (1..4) & Old_String (5..Last);
> 
> or, if Old_String(Bad_Char_Index) = offensive_character,
>   Old_String(Bad_Char_Index .. Last-1) := Old_String(Bad_Char_Index+1 .. 
>   Last);
>   Last := Last-1;


Yes you can do that, but then you are -not- deleting characters 
from a string, you are deleting characters from a variable
length string abstraction which is contained in two variables 
(Old_String, Last). This is essentially what Ada.Strings.Bounded
does of course.

Dale



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  0:25 How to delete charcters in a string? Anthony Wise
  2002-01-30  2:44 ` Steve Doiel
  2002-01-30  3:22 ` dale
@ 2002-01-30 11:21 ` Preben Randhol
  2002-01-30 15:15   ` Marin David Condic
  2002-01-31 14:47 ` Ted Dennison
  3 siblings, 1 reply; 19+ messages in thread
From: Preben Randhol @ 2002-01-30 11:21 UTC (permalink / raw)


On Wed, 30 Jan 2002 00:25:23 +0000, Anthony Wise wrote:
> hi
> (im new to ada by the way)
> 
> well supose there is a character in a string which i do not want to be seen 
> in the output.  i don't want to change it to anouther character but delete 
> it completely.

Is this homework?


-- 
Preben Randhol         �For me, Ada95 puts back the joy in programming.�



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  7:49     ` Dale Stanbrough
@ 2002-01-30 15:04       ` Marin David Condic
  0 siblings, 0 replies; 19+ messages in thread
From: Marin David Condic @ 2002-01-30 15:04 UTC (permalink / raw)


It seems like if all that is wanted is to get rid of some character
contained in the string without actually decreasing the size of the string
(just back padding with spaces or nulls or whatever...) then the best thing
to do is use the package Ada.Strings.Fixed. From my quick review of it you
have:

Move
Replace_Slice
Overwrite
Delete

All of which could be used to remove a particular character. Does that
address the original concern or was there a requirement to remove the array
position as well? (No need to build the proverbial "Brick Outhouse" if this
addresses the needs of an Ada newbie, eh? :-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Dale Stanbrough" <dstanbro@bigpond.net.au> wrote in message
news:dstanbro-836472.18481830012002@mec2.bigpond.net.au...
> tmoran@acm.org wrote:
>
>
> Yes you can do that, but then you are -not- deleting characters
> from a string, you are deleting characters from a variable
> length string abstraction which is contained in two variables
> (Old_String, Last). This is essentially what Ada.Strings.Bounded
> does of course.
>






^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30 11:21 ` Preben Randhol
@ 2002-01-30 15:15   ` Marin David Condic
  0 siblings, 0 replies; 19+ messages in thread
From: Marin David Condic @ 2002-01-30 15:15 UTC (permalink / raw)


If its homework, the answer "Look in ARM appendix A.4.3 at the package
Ada.Strings.Fixed" is either an acceptable answer for the assignment - or it
doesn't illustrate an understanding of string/array manipulation algorithms.
In either case, it seems like a reasonable answer to give a student that
either a) solves the problem or b) points at a possible solution. (id est,
duplicate the "Move" procedure with your own code.)

Didn't really sound like homework - more like "Is there a pre-fab Ada answer
to a common programming need?" But students should know we don't do the work
for them - unless, of course, they can afford rather large consulting fees.
:-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Preben Randhol" <randhol+abuse@pvv.org> wrote in message
news:slrna5fltm.13j.randhol+abuse@kiuk0156.chembio.ntnu.no...
>
> Is this homework?
>






^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-30  0:25 How to delete charcters in a string? Anthony Wise
                   ` (2 preceding siblings ...)
  2002-01-30 11:21 ` Preben Randhol
@ 2002-01-31 14:47 ` Ted Dennison
  2002-01-31 16:08   ` Larry Hazel
  2002-02-01  6:14   ` tmoran
  3 siblings, 2 replies; 19+ messages in thread
From: Ted Dennison @ 2002-01-31 14:47 UTC (permalink / raw)


"Anthony Wise" <iamwisey_@hotmail.com> wrote in message news:<mailman.1012350362.32618.comp.lang.ada@ada.eu.org>...
> (im new to ada by the way)
> 
> well supose there is a character in a string which i do not want to be seen 
> in the output.  i don't want to change it to anouther character but delete 
> it completely.

I've seen a lot of answers, but I'll throw mine in anyway because I
think there's a point that needs to be made.

Ada strings are *very* different from C strings, and it takes a bit of
getting used to. In C, strings are essentially a sequence of CHARs
with a null (0) at the end. In Ada, strings are an array of characters
of an exact range that *you* specify (by default, the entire array).
The string ends where your array (or slice of the array) ends. In
practice strings rarely change, so you can set your string to
perfectly fill the array, which makes Ada strings much easier to deal
with (and quicker) than their C counterparts. In the rare cases where
strings do change, you must keep a length index separately, or use one
of the alternate dynamic string types in Ada.Strings.*.

If you are using the String type for your strings, realize that these
strings are "fixed", and are best dealt with that way. That means that
rather than trying to remove a character, what you generally would
look to do is create a new string value (separate from the old one)
with the character removed. There's a routine in Ada.Strings.Fixed to
help with that, but if you know its index its just as easy to do it
with something like:
  My_String (My_String'first .. Char_Index - 1) & 
  My_String (Char_Index + 1 .. My_String'last);

However, I should say that solutions to this problem should go on the
back burner until you have dicovered that you are solving the right
problem in the first place. Perhaps you are, but often newbies are
not, and there's no ways to tell from your post. Since Ada and C
strings are so different, the techniques you may have learned for
dealing with dynamic C strings are liable to be completely
inappropriate for dealing with fixed Ada strings. So the first
question we need answered is *why* you want to remove a character from
the middle of your string.
 
-- 
T.E.D. 
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-31 14:47 ` Ted Dennison
@ 2002-01-31 16:08   ` Larry Hazel
  2002-02-01 15:59     ` Ted Dennison
  2002-02-01 17:05     ` Darren New
  2002-02-01  6:14   ` tmoran
  1 sibling, 2 replies; 19+ messages in thread
From: Larry Hazel @ 2002-01-31 16:08 UTC (permalink / raw)


Ted Dennison wrote:
> 
> "Anthony Wise" <iamwisey_@hotmail.com> wrote in message news:<mailman.1012350362.32618.comp.lang.ada@ada.eu.org>...
> > (im new to ada by the way)
> >
> > well supose there is a character in a string which i do not want to be seen
> > in the output.  i don't want to change it to anouther character but delete
> > it completely.
> 
> I've seen a lot of answers, but I'll throw mine in anyway because I
> think there's a point that needs to be made.
> 
> Ada strings are *very* different from C strings, and it takes a bit of
> getting used to. In C, strings are essentially a sequence of CHARs
> with a null (0) at the end. In Ada, strings are an array of characters
> of an exact range that *you* specify (by default, the entire array).
> The string ends where your array (or slice of the array) ends. In
> practice strings rarely change, so you can set your string to
> perfectly fill the array, which makes Ada strings much easier to deal
> with (and quicker) than their C counterparts. In the rare cases where
> strings do change, you must keep a length index separately, or use one
> of the alternate dynamic string types in Ada.Strings.*.
> 
> If you are using the String type for your strings, realize that these
> strings are "fixed", and are best dealt with that way. That means that
> rather than trying to remove a character, what you generally would
> look to do is create a new string value (separate from the old one)
> with the character removed. There's a routine in Ada.Strings.Fixed to
> help with that, but if you know its index its just as easy to do it
> with something like:
>   My_String (My_String'first .. Char_Index - 1) &
>   My_String (Char_Index + 1 .. My_String'last);
> 
> However, I should say that solutions to this problem should go on the
> back burner until you have dicovered that you are solving the right
> problem in the first place. Perhaps you are, but often newbies are
> not, and there's no ways to tell from your post. Since Ada and C
> strings are so different, the techniques you may have learned for
> dealing with dynamic C strings are liable to be completely
> inappropriate for dealing with fixed Ada strings. So the first
> question we need answered is *why* you want to remove a character from
> the middle of your string.
> 
Good points Ted.  It caused me to wonder.  Since a null character in Ada means
(essentially) "no character here", rather than end of string, could you just
replace the character you want to delete with a null character?

Larry



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-31 14:47 ` Ted Dennison
  2002-01-31 16:08   ` Larry Hazel
@ 2002-02-01  6:14   ` tmoran
  2002-02-01 15:56     ` Stephen Leake
  1 sibling, 1 reply; 19+ messages in thread
From: tmoran @ 2002-02-01  6:14 UTC (permalink / raw)


>the techniques you may have learned for dealing with dynamic C strings
>are liable to be completely inappropriate for dealing with fixed Ada strings.
  How would you delete a character from a C string?  Seems to me that's
probably harder that with an Ada string (lack of slice assignment),
unless, of course, you selectively copy to a new string.  And if you
really need in-band signalling, you don't have to have a Last variable,
but can put a null where your string logically ends, just like C.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-02-01  6:14   ` tmoran
@ 2002-02-01 15:56     ` Stephen Leake
  2002-02-01 17:53       ` Pascal Obry
  0 siblings, 1 reply; 19+ messages in thread
From: Stephen Leake @ 2002-02-01 15:56 UTC (permalink / raw)


tmoran@acm.org writes:

> >the techniques you may have learned for dealing with dynamic C
> >strings are liable to be completely inappropriate for dealing with
> >fixed Ada strings.

>   How would you delete a character from a C string?  Seems to me that's
> probably harder that with an Ada string (lack of slice assignment),

char *S1 = "ABCDEF";

strncpy (S1 + 3, S1 + 4, 3);

result in *S1 is "ABDEF".

No where near as pretty or readable as Ada, but just as short and
easy. And I've probably got the "src" and "dest" parameters swapped.
Man, I hate C :).

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-31 16:08   ` Larry Hazel
@ 2002-02-01 15:59     ` Ted Dennison
  2002-02-01 17:05     ` Darren New
  1 sibling, 0 replies; 19+ messages in thread
From: Ted Dennison @ 2002-02-01 15:59 UTC (permalink / raw)


Larry Hazel <lhhazel@otelco.net> wrote in message news:<3C596BE4.D0F1BFCB@otelco.net>...
> Good points Ted.  It caused me to wonder.  Since a null character in Ada means
> (essentially) "no character here", rather than end of string, could you just
> replace the character you want to delete with a null character?

If it truly means that. If you are writing the program that will
process the string, then you can certinaly make it mean that. But that
doesn't mean that
"Foo" & ASCII.NUL = "Foo"
will return true. So they are *not* the same in that sense. How a
device (like a terminal display) will handle a nul is up to it.

That's not the point though. Since C's strings are somewhat dynamic,
using them as storage while the contents are massaged into proper
place is encouraged. Thus algorithms that cause string values to be
modified are fairly natural in C. In Ada its usualy much more sensible
(and possible) to figure our your string's final value in one shot. If
you need intermediate steps, you'd usually want to use intermediate
strings. So algorithms that rely on mucking with string values in
place are discouraged.

My point is that one shouldn't try solving problems the C way in Ada.
As they say at NASA, "Never apply a Star Trek solution to a Babylon 5
problem". Newbies are quite likely to fall into such a trap, and I
haven't seen this one give his rationale for needing  a "delete one
character" solution so that I can believe otherwise. So the first
answer here shouldn't be "here's how you do that...", it should be
"Why do you need to do that?"

-- 
T.E.D.
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-01-31 16:08   ` Larry Hazel
  2002-02-01 15:59     ` Ted Dennison
@ 2002-02-01 17:05     ` Darren New
  1 sibling, 0 replies; 19+ messages in thread
From: Darren New @ 2002-02-01 17:05 UTC (permalink / raw)


Larry Hazel wrote:
> Since a null character in Ada means
> (essentially) "no character here", rather than end of string, could you just
> replace the character you want to delete with a null character?

Actually, that would be the "DEL" character. That's why it's at the high
end of the ASCII table, after all, because with all seven bits set, you
can overwrite any pattern of holes in a paper tape with it. ;-)

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
  The opposite of always is sometimes.
   The opposite of never is sometimes.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-02-01 15:56     ` Stephen Leake
@ 2002-02-01 17:53       ` Pascal Obry
  2002-02-18  3:48         ` David Thompson
  0 siblings, 1 reply; 19+ messages in thread
From: Pascal Obry @ 2002-02-01 17:53 UTC (permalink / raw)



Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:

> tmoran@acm.org writes:
> 
> > >the techniques you may have learned for dealing with dynamic C
> > >strings are liable to be completely inappropriate for dealing with
> > >fixed Ada strings.
> 
> >   How would you delete a character from a C string?  Seems to me that's
> > probably harder that with an Ada string (lack of slice assignment),
> 
> char *S1 = "ABCDEF";
> 
> strncpy (S1 + 3, S1 + 4, 3);
> 
> result in *S1 is "ABDEF".
> 
> No where near as pretty or readable as Ada, but just as short and
> easy. And I've probably got the "src" and "dest" parameters swapped.
> Man, I hate C :).

And that is not what you wanted too :)

 result in *S1 is "ABDEFF".

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-02-01 17:53       ` Pascal Obry
@ 2002-02-18  3:48         ` David Thompson
  2002-02-18 19:44           ` Stephen Leake
  0 siblings, 1 reply; 19+ messages in thread
From: David Thompson @ 2002-02-18  3:48 UTC (permalink / raw)


Pascal Obry <p.obry@wanadoo.fr> wrote :
>
> Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:
>
> > tmoran@acm.org writes:
...
> > >   How would you delete a character from a C string?  Seems to me that's
> > > probably harder that with an Ada string (lack of slice assignment),
> >
> > char *S1 = "ABCDEF";
> >
> > strncpy (S1 + 3, S1 + 4, 3);
> >
> > result in *S1 is "ABDEF".
> >
No it's not.  All C arrays, including strings, are zero-origin,
so _if_ this worked it would produce ABCEF.  But:

1) you can't legally modify (store to) a string literal value.
_Some_ implementations put them in readonly storage
and this will fault.  _Some_ implementations share storage
for identical(ly-suffixed) values, so modifying one changes
the other(s) -- like the classic FORTRAN (II? IV?) bug of
changing say the constant 1 to be 2.  In C++ string literal
values are at least qualified const, which couldn't be done
in Standard C for compatibility with the pre-existing code
base, so _some_ (simple) violations of this rule are caught
by the compiler, but even in C++ there is a legal though
nonpreferred conversion to non-const char pointer.

Note char foo[] = "ABCDEF" is different.  That allocates
space and _initializes_ it by copying the literal value --
at least notionally, for static-duration variables the copy
is often embedded in process creation -- and it can then
be legally modified; but see next.

2) all the <string.h> routines have Undefined Behavior
(in Ada terms, are erroneous) for overlapping buffers,
with the single exception of memmove().  This means
in theory _anything_ is permissible; in practice, the
likely problem is that fetches and/or stores are reordered
and you do get a deterministic value, just the wrong one.

> > No where near as pretty or readable as Ada, but just as short and
> > easy. And I've probably got the "src" and "dest" parameters swapped.
> > Man, I hate C :).
>
Actually (dest,src,len) is the only part you got right.
I decline to guess what if anything this signifies.

> And that is not what you wanted too :)
>
>  result in *S1 is "ABDEFF".
>
That isn't right either.  See above.

--
- David.Thompson 1 now at worldnet.att.net






^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: How to delete charcters in a string?
  2002-02-18  3:48         ` David Thompson
@ 2002-02-18 19:44           ` Stephen Leake
  0 siblings, 0 replies; 19+ messages in thread
From: Stephen Leake @ 2002-02-18 19:44 UTC (permalink / raw)


"David Thompson" <david.thompson1@worldnet.att.net> writes:

> Pascal Obry <p.obry@wanadoo.fr> wrote :
> >
> > Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:
> >
> > > tmoran@acm.org writes:
> ...
> > > >   How would you delete a character from a C string?  Seems to me that's
> > > > probably harder that with an Ada string (lack of slice assignment),
> > >
> > > char *S1 = "ABCDEF";
> > >
> > > strncpy (S1 + 3, S1 + 4, 3);
> > >
> > > result in *S1 is "ABDEF".
> > >
> No it's not.  All C arrays, including strings, are zero-origin,
> so _if_ this worked it would produce ABCEF.  But:

Ok. Never post code that hasn't been run, even if it is C :).

> 1) you can't legally modify (store to) a string literal value.
> _Some_ implementations put them in readonly storage and this will
> fault. _Some_ implementations share storage for
> identical(ly-suffixed) values, 

Right. I should have added an extra strcpy to a variable.

> Note char foo[] = "ABCDEF" is different.  That allocates
> space and _initializes_ it by copying the literal value --
> at least notionally, for static-duration variables the copy
> is often embedded in process creation -- and it can then
> be legally modified; but see next.

Hmm. I guess this is a case where array is _not_ defined in terms of
pointer. I had not noticed that before. Guess I can learn stuff even
about C still :).

> > > No where near as pretty or readable as Ada, but just as short and
> > > easy. And I've probably got the "src" and "dest" parameters swapped.
> > > Man, I hate C :).
> >
> Actually (dest,src,len) is the only part you got right.
> I decline to guess what if anything this signifies.

Me too :).

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2002-02-18 19:44 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-30  0:25 How to delete charcters in a string? Anthony Wise
2002-01-30  2:44 ` Steve Doiel
2002-01-30  3:22 ` dale
2002-01-30  6:37   ` tmoran
2002-01-30  7:49     ` Dale Stanbrough
2002-01-30 15:04       ` Marin David Condic
2002-01-30 11:21 ` Preben Randhol
2002-01-30 15:15   ` Marin David Condic
2002-01-31 14:47 ` Ted Dennison
2002-01-31 16:08   ` Larry Hazel
2002-02-01 15:59     ` Ted Dennison
2002-02-01 17:05     ` Darren New
2002-02-01  6:14   ` tmoran
2002-02-01 15:56     ` Stephen Leake
2002-02-01 17:53       ` Pascal Obry
2002-02-18  3:48         ` David Thompson
2002-02-18 19:44           ` Stephen Leake
     [not found] <F207EAsx2Pwf500RR1h00019d09@hotmail.com>
2002-01-30  1:16 ` Eric Merritt
2002-01-30  1:16 ` Eric Merritt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox