473,387 Members | 3,801 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,387 software developers and data experts.

Erasing an Array member in C

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 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. I am nit sure if C has STL erase( ) as in C++. Any idea of using erase and if so how would it work for the above example (no need to write full code just important bits).

Best regards,

Hefty
Jul 27 '07 #1
3 2521
gpraghuram
1,275 Expert 1GB
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 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. I am nit sure if C has STL erase( ) as in C++. Any idea of using erase and if so how would it work for the above example (no need to write full code just important bits).

Best regards,

Hefty
HI,
There is no readymade functions available to erase elements in an array.
What u have to do is traverse through the array and if u find the element in array is invalid then move the subsequent element to the current position.

Raghuram
Jul 27 '07 #2
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 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. I am nit sure if C has STL erase( ) as in C++. Any idea of using erase and if so how would it work for the above example (no need to write full code just important bits).

Best regards,

Hefty
I think You have to write a function of your own to carry out this task.

I suggest you my own way of doing it.

Have a function with parameters, the parameters should be Array's subscript
values.

Use a for Loop to prepone the values which are after the position mentioned.

For Ex:
Expand|Select|Wrap|Line Numbers
  1. void func1(int *arr, int pos1) // if you put more positions then assign default values so that it can work for lesser parameters also
  2. {
  3.   for(int j=pos1,k=pos1+1;arr[k]!='\0';j++,k++)
  4.    {
  5.         arr[j] = arr[k];
  6.    }
  7.         arr[j] = arr[k];
  8. }
  9.  
Confirm whether this is the one you are looking for...

Regards,
Girish.
Jul 27 '07 #3
Thanks this what I was after. But I could not understand what the last line of your code is doing !!!.

Best regards,

Hefty


I think You have to write a function of your own to carry out this task.

I suggest you my own way of doing it.

Have a function with parameters, the parameters should be Array's subscript
values.

Use a for Loop to prepone the values which are after the position mentioned.

For Ex:
Expand|Select|Wrap|Line Numbers
  1. void func1(int *arr, int pos1) // if you put more positions then assign default values so that it can work for lesser parameters also
  2. {
  3.   for(int j=pos1,k=pos1+1;arr[k]!='\0';j++,k++)
  4.    {
  5.         arr[j] = arr[k];
  6.    }
  7.         arr[j] = arr[k];
  8. }
  9.  
Confirm whether this is the one you are looking for...

Regards,
Girish.
Jul 27 '07 #4

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

Similar topics

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...
3
by: Kaz Kylheku | last post by:
Given some class C with array T x, is it possible to get a pointer-to-data-member to one of the elements? &C::x gives us a pointer-to-member-array: T (C::*). But I just want to get a T C::*...
6
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph...
10
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
2
by: Simon Morgan | last post by:
I hope this isn't OT, I looked for a newsgroup dealing purely with algorithms but none were to be found and seeing as I'm trying to implement this in C I thought this would be the best place. I...
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...
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
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: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.