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

Deleting Array Element

P: n/a
How can I delete one or more elements of an array.
let a[]={1,2,3,4,5} Now i want to send the third element '3' to an
array b[10] and remove the element from a.

How can I do it?

Jun 13 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Umesh wrote On 06/13/07 10:46,:
How can I delete one or more elements of an array.
let a[]={1,2,3,4,5} Now i want to send the third element '3' to an
array b[10] and remove the element from a.

How can I do it?
You cannot.

The array has five elements, a[0] through a[4], and
there is no way to change that. You can, at best, change
the values that are stored in those elements; for example,
you might change them to { 1, 2, 4, 5, -1 }. But you
cannot make the elements "go away."

--
Er*********@sun.com
Jun 13 '07 #2

P: n/a
How can I remove duplicate entries from an array?

Jun 13 '07 #3

P: n/a
Umesh said:
How can I remove duplicate entries from an array?
By replacing them with unique entries.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 13 '07 #4

P: n/a
Umesh wrote On 06/13/07 11:35,:
How can I remove duplicate entries from an array?
The message to which your query is a response
explained why you cannot remove elements from an
array. You must have seen the message -- you posted
a reply to it -- but did you read it?

--
Er*********@sun.com
Jun 13 '07 #5

P: n/a
Umesh wrote:
How can I remove duplicate entries from an array?
Perhaps an array is the wrong choice for your data and algorithm? You
might be thinking of a linked-list, which can be built on top of an
array, if you like.
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 13 '07 #6

P: n/a
On 13 Jun, 16:56, Eric Sosman <Eric.Sos...@sun.comwrote:
Umesh wrote On 06/13/07 11:35,:
How can I remove duplicate entries from an array?

The message to which your query is a response
explained why you cannot remove elements from an
array. You must have seen the message -- you posted
a reply to it -- but did you read it?
Yours wasn't a response which fixed his perceived problem, so he
ignored it and raised a new issue. What's surprising there?

Jun 13 '07 #7

P: n/a

Umesh wrote:
How can I delete one or more elements of an array.
let a[]={1,2,3,4,5} Now i want to send the third element '3' to an
array b[10] and remove the element from a.

How can I do it?
>From what I understand of the question, you want to be able to delete
elements from an array (i.e. resize the array), much like lists in
Python, arrays in Perl or vectors in C++ or Java.

You cannot do this directly in C. What you can do however is to shift
the elements 4 and 5 one place to the left and treat the last element
as a garbage value. The space taken up by the array would still be the
same, but you can go on treating this as a 4 element array in the rest
of your program. This is an overly simplified solution to the more
general problem. To have truly resizable data structure that has all
the properties of an array, you would have to dynamically allocate and
then reallocate memory as your array grows or shrinks.

Jun 13 '07 #8

P: n/a
Eric Sosman wrote:
Umesh wrote On 06/13/07 11:35,:
How can I remove duplicate entries from an array?

The message to which your query is a response
explained why you cannot remove elements from an
array. You must have seen the message -- you posted
a reply to it -- but did you read it?

Why does anyone still bother with this guy. He's either trolling, or
perversely determined to ignore the advice given. Either way, a huge
waste of time.


Brian
Jun 13 '07 #9

P: n/a
Default User said:
Eric Sosman wrote:
>Umesh wrote On 06/13/07 11:35,:
How can I remove duplicate entries from an array?

The message to which your query is a response
explained why you cannot remove elements from an
array. You must have seen the message -- you posted
a reply to it -- but did you read it?


Why does anyone still bother with this guy. He's either trolling, or
perversely determined to ignore the advice given. Either way, a huge
waste of time.
I had him plonked, actually. Then I noticed, through context quoted by
Martin, that he'd started *giving* advice, at which point I considered
that it was more important to ensure that he didn't mislead newbies
than that he didn't annoy me.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 13 '07 #10

P: n/a
Richard Heathfield wrote:
Default User said:
Eric Sosman wrote:
Umesh wrote On 06/13/07 11:35,:
How can I remove duplicate entries from an array?

The message to which your query is a response
explained why you cannot remove elements from an
array. You must have seen the message -- you posted
a reply to it -- but did you read it?

Why does anyone still bother with this guy. He's either trolling, or
perversely determined to ignore the advice given. Either way, a huge
waste of time.

I had him plonked, actually. Then I noticed, through context quoted
by Martin, that he'd started giving advice, at which point I
considered that it was more important to ensure that he didn't
mislead newbies than that he didn't annoy me.
Ah, valid point.

Brian
Jun 13 '07 #11

P: n/a
Umesh <fr****************@gmail.comwrites:
How can I delete one or more elements of an array.
let a[]={1,2,3,4,5} Now i want to send the third element '3' to an
array b[10] and remove the element from a.

How can I do it?
Use a different language. This will require using a different
newsgroup. Bye!

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 13 '07 #12

P: n/a

"Umesh" ("fraternity disposal aatt gmail dott com")
wrote:
How can I delete one or more elements of an array.
Umesh, Umesh, Umesh. First you go to comp.lang.c++ and
spam the group with nonsensical questions, then you come
to comp.lang.c and ask questions that are answered in the
first 10 pages of ANY good (or even mediocre) book on C.
It's like wasting a calculus professor's time by asking him,
"What's 3 plus 4? What's 9 divided by 2? What's a prime
number? Is 42 a prime number?" He's going to shove you
out his office door.

Get a book on C, Umesh. Read it. Learn something about
the language. THEN come here and talk to us about it.
Ok? Pleeeeeeeze?

--
Cheers,
Robbie Hatley
lone wolf aatt well dott com
triple-dubya dott Tustin Free Zone dott org
Jun 14 '07 #13

P: n/a
On Jun 13, 10:35 am, Umesh <fraternitydispo...@gmail.comwrote:
How can I remove duplicate entries from an array?
Change one of the duplicate values to a different value. As was
explained before, you cannot remove an array element; you may only
change its value.
Jun 14 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.