RSS Forums RSS
Please support our C advertiser: Programming Forums

Counter issues

Join Date: Jul 2004
Location: Md
Posts: 17
Reputation: nufanvandal is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
nufanvandal nufanvandal is offline Offline
Newbie Poster

Counter issues

  #1  
Jul 22nd, 2004
Hey everyone.

im having issues with my for loop:
basically it reads in from a file using unix redirection and stores the integers into an array, that all works fine, but i need to return the number of integers that were read in, and logically i thought this would work, but i just get some crazy number. thanks for any help.

 /*Reads the data from .dat file*/  
   for(i = 0; i <= MAX || ageList[i] != 0; i++)
   {
      
      scanf("%d",&ageList[i]);
      counter += 1;
   }

The whole function:

int FillAgeList(int ageList[])
{
   
   int i; 
   int counter;
   
   /*Initializes the array*/
   for(i = 0; i <= MAX; i++)
   {
      ageList[i] = -1;
   }

   counter = 0; 
   /*Reads the data from .dat file*/  
   for(i = 0; i <= MAX || ageList[i] != 0; i++)
   {
      
      scanf("%d",&ageList[i]);
      counter += 1;
   }

   /*Prints the integers*/
   for(i = 0; i <= MAX && ageList[i] != 0;i++)
   {
    	 printf("%d\n",ageList[i]);
   }
      return(counter);
}    
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:05 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC