Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

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.

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

![]() |
Extract web data
|
DOS Batch: Remove Trailin...
|

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