Sorry if it seems pretty simple to solve. But I am really new to C and have tried a lot, but I cant figure out how to stop the scanner from reading more integers than the max limit. I have a file which has 22 integers, but I want the array to store only 20 integers from the file. But still it's reading all integers. Any tip would be really valuable for me :/ Thanks a lot
int *array = malloc(20* sizeof(int));
while(fscanf(fp,"%d",&array[i])!=EOF)
{
printf("%d\n",array[i]);
if(*array <= 20){
i++;
}
}