/**********************************************/
/*    C Program Template                      */
/*                                            */
/*   1) Output the data                       */
/*                                            */
/*          2016/04/13 Masayuki Akiyama       */
/**********************************************/

#include "template.h"

void  main(argc, argv)
int    argc;
char  *argv[];
{

   /*** Basic Variables ***/

   FILE   *file;
  
   /*** struct for list of data ***/
   int    n;
   char   line[1000];
   char   datastring[30][30];

   /*** data from input file          ***/
   char  name[100];
   float x;
   float y;

   float result;

   if(argc!=2){
     fprintf(stderr, "Usage : template [list1] \n");
     exit(0);
   }

   /*** open a file ***/
   file = fopen( argv[1], "r");

   if(file > 0){
   /*** read one line with fgets ***/
       while(fgets (line, sizeof(line), file)){

   /*** break a line into 3 datastring ***/
          n = sscanf(line, "%s %s %s ",
                  datastring[0],datastring[1],datastring[2]);

   /*** copy datastring to 1 string, and 2 floats ***/
          sprintf(name, "%s", datastring[0]);
          x = atof(datastring[1]);
          y = atof(datastring[2]);

   /*** calculation ***/
          result = test_calc( x, y );

   /*** print out result ***/
          fprintf(stdout, "%s %f %f %f \n", name, x, y, result );
      }
   }
   return;
}
