Please support our C advertiser: Programming Forums
Views: 1898 | Replies: 2
•
•
Join Date: Jul 2004
Location: Md
Posts: 17
Reputation:
Rep Power: 5
Solved Threads: 0
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.
The whole function:
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);
} •
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Threaded Mode