This code is supposed to get integers from a file which is finput and sort it and gets the first integer in the file which is the number of integers to be sorted and the integers that follow are the integers to be sorted. I don't get how fgets and sscanf work together. Can someone explain how fgets and sscanf work in this code?
FILE *finput;
int *array_int, c1, no_elem;
char numlines[500];
fgets(numlines, 500, finput);
array_int = (int *)malloc(sizeof(int)*no_elem);
if ((sscanf(numlines, "%d", &no_elem) == 1) && array_int!= NULL)
{
for(c1=0; fgets(numlines, 500, finput) != NULL; )
{
if (sscanf(numlines, "%d", &array_int[c1])==1)
{
++c1;
}
}
}