Computing.Net > Forums > Programming > array manipulation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

array manipulation

Reply to Message Icon

Name: enogogo
Date: January 23, 2004 at 07:12:20 Pacific
OS: unix
CPU/Ram: 2
Comment:

i need a c++ function such that:

i have an array of integers
eno[] =[1,3,0,4,5,0,0,8,3,4,0] something and i want to pull out the zeros and set up an other array
eno2[]=[1,3,4,5,8,4], can anyone help me?



Sponsored Link
Ads by Google

Response Number 1
Name: enogogo
Date: January 23, 2004 at 07:19:23 Pacific
Reply:

correction: eno2[]=[1,3,4,5,8,3,4]


0

Response Number 2
Name: gpp
Date: January 23, 2004 at 08:02:35 Pacific
Reply:

This shouldnt be too hard.. You just need to loop through the array(eno[]) and every time you find a non-zero, add it to the end of eno2[]. eno2[] should probably be dynamic so you dont waste a lot of memory.. only problem is I'm not sure how to resize the array in C++. I used C back when I wrote this, and had to use realloc to change the size of the array... guess you'll have to do some searching.


0

Response Number 3
Name: Infinite Recursion
Date: January 23, 2004 at 10:40:14 Pacific
Reply:

GPP's method is probably how you need to approach this problem. Take the initial array, loop through it and only extract the ones you need and assign them into another array.

If you really want "ease" then, use STL (SGI's standard template library). I believe the VECTOR will allow you to do just this, and the size does not need to be defined (if it attempts to go out of bounds, it doubles in size).

If you don't want to use STL... search google for 'dynamic arrays C++' and you should find what you need.

IR


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Extract web data DOS Batch: Remove Trailin...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: array manipulation

help needed on c++ www.computing.net/answers/programming/help-needed-on-c/7864.html

C Arrays www.computing.net/answers/programming/c-arrays/8161.html

Object array in Java www.computing.net/answers/programming/object-array-in-java/11087.html