Deleting Array Element

U

Umesh

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?
 
E

Eric Sosman

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."
 
E

Eric Sosman

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?
 
C

Clever Monkey

Umesh said:
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.
 
M

mark_bluemel

Umesh wrote On 06/13/07 11:35,:


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?
 
M

Muntasir Azam Khan

Umesh said:
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.
 
D

Default User

Eric said:
Umesh wrote On 06/13/07 11:35,:

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
 
R

Richard Heathfield

Default User said:
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.
 
D

Default User

Richard said:
Default User said:


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
 
K

Keith Thompson

Umesh said:
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!
 
R

Robbie Hatley

"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?
 
J

John Bode

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.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top