You don't need to collect the items (i.e. you don't need the array), you find the minimum aged person on the fly:
(beware, the following code must be improved for reliability)
#include <stdio.h>
#include <string.h>
#include <limits.h>
struct Person
{
char name[40];
int age;
char sex[10];
};
int main()
{
struct Person current, youngest;
youngest.age = INT_MAX;
FILE *fp;
int rc = -1;
fp = fopen("candidate.txt","r");
if ( ! (fp =fopen("candidate.txt","r")))
{
printf("Unable to open the input file...\n\n");
return -1;
}
for(;;)
{
int rc = fscanf(fp,"%s %d %s", current.name, ¤t.age, current.sex);
if ( rc != 3 ) break;
if ( youngest.age > current.age )
{
youngest.age = current.age;
strcpy(youngest.name, current.name);
strcpy(youngest.sex, current.sex);
}
}
if ( youngest.age != INT_MAX)
{
printf("%s is the yougest whose age is %d\n", youngest.name, youngest.age);
rc = 0;
}
else
{
printf("Unable to retrieve data from the file\n");
}
fclose(fp);
return rc;
}