473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Erasing Array elements in C

Hi Guys,

I am trying to eliminate certain elements off an array or vector in C without affecting other elements. Any idea of how this can be done neatly. For example:

Input Array : 8 7 6 5 **0** 9 **0** 8 7

Ouput Array: 8 7 6 5 9 8 7

Any idea how a C function can be written to execute such functionality.

Best regards,

Hefty
Jul 26 '07 #1
4 1776
ravenspoint
111 100+
There is no need to write such a function. The vector and other STL containers provide the method erase() to do this.
Jul 26 '07 #2
There is no need to write such a function. The vector and other STL containers provide the method erase() to do this.
Hi ravenpoint,

I am working in C and I am not sure if it has an STL as this is available in C++. Could you please advise on how would I use erase in this context and how would I index the rest of the array members following eliminating one of them.

For example:

Input array: 0 1 7 9 8 **4** 3
Ouptut array: 0 1 7 9 8 3

Thanks,

Hefty
Jul 26 '07 #3
just a suggestion:
y don't u replace the elements tat u don't want with a specific character which u r not expecting to be part of ur input eg: '?'
then do a loop to print every thing but the '?'

warning: can b a slow program with large data

best of luck
Jul 27 '07 #4
ravenspoint
111 100+
Hi ravenpoint,

I am working in C and I am not sure if it has an STL as this is available in C++.
Since you mentioned vector in your opriginal post ( OP ) I assumed that you had STL.

You should check to see if you do, since it is extremely helpful and will save you many hours of work.

If you do not have STL, then getchar's scheme sounds workable. Have you tried it?
Jul 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Owen Brydon | last post by:
Hi, Is the following code legal? g++ 3.2 barfs on it, although it seems fine to me. #include <map> using std::map; int main()
8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
12
by: Tescobar | last post by:
Over one year ago somebody asked here: how to remove selected elements from list in a loop?. The answer was as follows: for( it = l.begin(); it != l.end; ) { if(...) it = l.erase(it); else...
5
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling...
11
by: eeykay | last post by:
Hello, I am facing a starnge problem while erasing the last member in a vector. I am using VC++ .NET 2002 complier. I have vector of CComPtr<..> (irrelevant here), and then I iterate over the...
5
by: ma740988 | last post by:
For starters, Happy New Year to all!! I created a vector of pairs where pair first is a primitive and pair second is a vector of ints. So now: # include <iostream> # include <vector>
3
by: =?iso-8859-1?q?Erik_Wikstr=F6m?= | last post by:
I have some code where there's this vector of pointers to objects and I need to delete and erase some of them, the problem is that to know which I need to iterate through the vector and I'm trying...
3
by: hefty1985 | last post by:
Hi Guys, I think I put the question in the wrong format in the previous time .I am trying to eliminate certain elements off an array or vector in C without affecting other elements. Any idea of...
3
by: Angus | last post by:
If I want to erase all list items with a value of say 3 as below: std::list<intmylist; mylist.push_back(3); mylist.push_back(4); mylist.push_back(5); mylist.push_back(6); ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.