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);
}