// 09212009.cpp, P H Anderson, Sept 21, '09

#include <stdio.h>
#include <stdlib.h>

int get_array(float a[]);
void print_array(float a[], int num_ele);

FILE *f;

int main(void)
{
    float a[100];
    int num_ele;
    
    num_ele = get_array(a);
    printf("%i\n", num_ele);
    print_array(a, num_ele);
    
    system("pause");
}

int get_array(float a[])
{
    int n = 0;
    if ((f = fopen("c:\\data.txt", "rt")) == NULL)
    {
        // file does not exist   
        return(0);
    }
    // else
    for (n= 0; n<100; n++)
    {
        if (fscanf(f, "%f", &a[n]) != 1)
        {
            fclose(f);
            return(n);
        }
    }
}            
  
void print_array(float a[], int num_ele)
{
    int n;
    for (n=0; n<num_ele; n++)
    {
        printf("%.2f\t", a[n]);
    }
    printf("\n");
}           

#ifdef OUTPUT
93
8.66    8.30    7.90    7.46    6.99    6.49    5.95    5.39    4.80    4.19
3.56    2.92    2.26    1.59    0.91    0.23    -0.46   -1.14   -1.81   -2.48
-3.13   -3.77   -4.40   -5.00   -5.58   -6.13   -6.66   -7.15   -7.61   -8.04
-8.42   -8.77   -9.08   -9.34   -9.57   -9.74   -9.87   -9.96   -10.00  -9.99
-9.94   -9.83   -9.69   -9.50   -9.26   -8.98   -8.66   -8.30   -7.90   -7.46
-6.99   -6.49   -5.95   -5.39   -4.80   -4.19   -3.56   -2.92   -2.26   -1.59
-0.91   -0.23   0.46    1.14    1.81    2.48    3.13    3.77    4.40    5.00
5.58    6.13    6.66    7.15    7.61    8.04    8.42    8.77    9.08    9.34
9.57    9.74    9.87    9.96    10.00   9.99    9.94    9.83    9.69    9.50
9.26    8.98    8.66
Press any key to continue . . .
#endif