Stuck in loop that should stop after end of file - C
<p>I can't seem to figure out how to fix my loop in main, so that it stops at the end of file. I thought that by returning a value from my scanning functions, it would cause the loop to stop at the end of file. It seems that the variable result is not being returned.</p>

<p>There may be another way of looping the two function calls so they stop at end of file?</p>

<p>There is a commented out section that does read till end of file, but I am trying to accomplish this using the print and scan functions that have been created.</p>

<p>Code so far.... </p>

<pre><code>#include &lt;stdio.h&gt;

#define STRSIZE 20

/* Structure definitions   */
typedef struct {
        int     month,
                day,
                year;
} date_t;

typedef struct {
        double  capacity,
                current;
} tank_t;

typedef struct {
        char    make[STRSIZE],
                model[STRSIZE];
        int     odometer;
        date_t  manuf,
                purch;
        tank_t  tank;
} auto_t;

/* Function prototypes   */



int scan_date(date_t *date, FILE *inp);
int scan_tank(tank_t *tank, FILE *inp); 
int scan_auto(auto_t *vehicle, FILE *inp); 


void print_date(date_t date); 
void print_tank(tank_t tank);
void print_auto(auto_t vehicle); 

int main()
{
    auto_t      vehicle;
    date_t      date;
    tank_t      tank;
    int         i=0,
                result=1;

    FILE *inp = fopen("autos.txt","r");                /* defining file input    */

    /* Check to make sure input file is found and readable.  */
    if(inp==NULL){
        printf("Error: Input file - autos.txt - not found!\n");

        getch();
        return 0;
    }

    printf("Vehicle   Vehicle  Odometer  Date        Date          Tank       Current\n");
    printf("Make      Model    Reading   Purchased   Manufactured  Capacity   Fuel Level\n");
    printf("\n----------------------------------------------------------------------------\n");


 /*******************COMMENTED OUT*************************************
    while(status&gt;0){
         status=fscanf(inp, "%s%s%d%d%d%d%d%d%d%lf%lf", vehicle.make,
                                                        vehicle.model,
                                                        &amp;vehicle.odometer,
                                                        &amp;vehicle.manuf.month,
                                                        &amp;vehicle.manuf.day,
                                                        &amp;vehicle.manuf.year,
                                                        &amp;vehicle.purch.month,
                                                        &amp;vehicle.purch.day,
                                                        &amp;vehicle.purch.year,
                                                        &amp;vehicle.tank.capacity,
                                                        &amp;vehicle.tank.current);

    if(status==11){
         printf("%-10s%-9s%-10d%2d/%d/%-6d%2d/%d/%-8d%-11.1lf%.1lf\n", vehicle.make,
                                                                    vehicle.model,
                                                                    vehicle.odometer,
                                                                    vehicle.manuf.month,
                                                                    vehicle.manuf.day,
                                                                    vehicle.manuf.year,
                                                                    vehicle.purch.month,
                                                                    vehicle.purch.day,
                                                                    vehicle.purch.year,
                                                                    vehicle.tank.capacity,
                                                                    vehicle.tank.current);
         i++;}

     else if(status &lt;11 &amp;&amp; status&gt;0){
         printf("\nInvalid Input - The next line of data is corrupt.\n");
     }                                              
     }                                                  
******************************************************************************/ 


   while(result&gt;0){

        scan_auto(&amp;vehicle, inp);

        if(result==11){

            print_auto(vehicle);
        }

        else if(result &lt;11 &amp;&amp; result&gt;0){

            printf("\nInvalid Input - The next line of data is corrupt.\n");
        }                                              
     }  

    getch();
    return 0;
}

/*********************************************************************************/   
int scan_date(date_t *date, FILE *inp)
{
    int result = fscanf(
        inp,
        "%d%d%d",
        &amp;(date-&gt;day),
        &amp;(date-&gt;month),
        &amp;(date-&gt;year));

    return (result == 3);
}

/*********************************************************************************/
int scan_tank(tank_t *tank, FILE *inp)
{
    int result = fscanf(
        inp,
        "%lf%lf",
        &amp;(tank-&gt;capacity),
        &amp;(tank-&gt;current));


    return (result == 2);

}

/*********************************************************************************/
int scan_auto(auto_t *vehicle, FILE *inp)
{
    int result = fscanf(
        inp,
        "%s%s%d",
        vehicle-&gt;make,
        vehicle-&gt;model,
        &amp;(vehicle-&gt;odometer));

    result += scan_date(&amp;(vehicle-&gt;purch), inp);
    result += scan_date(&amp;(vehicle-&gt;manuf), inp);
    result += scan_tank(&amp;(vehicle-&gt;tank), inp);

    return (result = 11);
}
/*********************************************************************************/
void print_auto(auto_t vehicle)
{
    printf("\n%-10s%-9s%-10d", vehicle.make,
                             vehicle.model,
                             vehicle.odometer);
    print_date(vehicle.purch); 
    print_date(vehicle.manuf);
    print_tank(vehicle.tank);



} 

/*********************************************************************************/

void print_date(date_t date)
{
     printf("%1d/%d/%-7d", date.day,
                           date.month,
                           date.year);

}     

/*********************************************************************************/

void print_tank(tank_t tank)
{
        printf("  %-11.1lf%.1lf", tank.capacity, 
                                tank.current);

} 
</code></pre>

<p>Here is the autos.txt file it uses....</p>

<pre><code>Mercury     Sable   99842   1   18  2001    5   30  1991    16  12.5
Mazda       Navajo  123961  2   20  1993    6   15  1993    19.3    16.7
Ford
</code></pre>

<p>I left an extra name in there, as to trigger an error message for the user to check the file to make sure its complete.</p>