GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Oct-2003, 10:38
wolfgangaz wolfgangaz is offline
New Member
 
Join Date: Oct 2003
Posts: 1
wolfgangaz is an unknown quantity at this point

arrays in c


say i have an array with the following elements set: a[2] = 1, a[5] = 4, a[7] = 2. i want to go thru all its elements and print them on the screen (or whatever). i know c has 'foreach', but the c installation that i have to use does not have 'contain.h' (i think 'foreach' is from that lib). could you offer a solution .. how to go thru all array elements if there are gaps in the indexing. thank you.
  #2  
Old 26-Oct-2003, 04:52
Dawis Dawis is offline
Awaiting Email Confirmation
 
Join Date: Oct 2003
Location: Latvia, Ogre
Posts: 7
Dawis is an unknown quantity at this point
As far as I know every variable holds some value, wether you want it or not.. I you have not refered to this wariable jet the value it may hold can be very unpredictable - some address of the memory and such..
one solution to your problem could be for example to give all elements of array spesific values before using it, so afterwards those elements you have used will hold diferent value..
For example:
CPP / C++ / C Code:
int a[10];
for (int i=0; i<10; i++) a[i]=-1000;
....
a[4]=5;
...
a[2]=18;
...
//and now you want to read all the values form array
for
for (int i=0; i<10; i++) 
     {
        if (a[i]!=-1000) cout<<a[i]<<endl;
      }
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extra null element in an array samtediou MySQL / PHP Forum 2 11-Dec-2003 11:52
Arrays Andrew MySQL / PHP Forum 2 26-Jan-2003 02:50

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:33.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.