// Program 08312009.cpp - Illustrates how to write to a file. 
// P H Anderson, Aug 31, '09

#include &;t;stdio.h>
#include <stdlib.h>
#include <math.h>

#define NUM 100

FILE	*f1;		// global declaration	

int main(void)
{
	int n;
	float x, y;
    
	f1=fopen("output.dta", "wt");	 // open file for writing text
	
	if (f1 == NULL)
	{
       printf("Error in opening file");
    }
    
    else
    {
 	   for (n=0; n<NUM; n++)
	   {
           x = - 2.0 * M_PI + 4 * M_PI * n / NUM;
           y = sin(x);
	 	   printf("%f\t%f\n", x, y);
		   fprintf(f1, "%f, %f\n", x, y); // similar to printf
	   }
	   fclose(f1);   // always close prior to leaving a routine.
    }   
    system("pause");
    system("type output.dta | more");
      
}

#ifdef JUNK
"Of the roughly 130 million jobs in the U.S., only 20%, or 26 million, pay 
more than $60,000 a year. The other 80% pay an average of $33,000."

   float x1, x2;
   char op;
   
   scanf("%f %c %f", &x1, &op, &x2);    
#endif