/* PROGRAM testprogram --- testprogram argument1 argument2 < infile > outfile --- A barebones program that reads a couple arguments, reads a file, does some simple math, and outputs another file. * argument1 = just a number * argument2 = another number * < infile = file containing two columns * > outfile = output file */ #include #include #include #define sqr(x) ((x)*(x)) #define PI (3.141592) int main(int argc, char *argv[]) { /*---Declare-variables-------------------------------------*/ int Nmax,Nfile,i,*column1 ; double argument1,argument2,x,y,z,*column2 ; /*---Read-arguments----------------------------------------*/ sscanf(argv[1],"%lf",&argument1) ; sscanf(argv[2],"%lf",&argument2) ; /*---Print-arguments---------------------------------------*/ fprintf(stderr,"testprogram> You typed %f and %f\n",argument1,argument2) ; /*---Do-some-math-and-print--------------------------------*/ x = argument1 + argument2 ; y = argument1 * argument2 ; fprintf(stderr,"testprogram> Their sum and product is %f and %f\n",x,y) ; /*---Allocate-arrrays--------------------------------------*/ Nmax=1000 ; column1=(int *) calloc(Nmax,sizeof(int)) ; column2=(double *) calloc(Nmax,sizeof(double)) ; /*---Read-infile-------------------------------------------*/ i=0 ; while(fscanf(stdin,"%d %lf",&column1[i],&column2[i])!=EOF) { i++ ; } Nfile=i ; fprintf(stderr,"testprogram> file has %d lines in it\n",Nfile) ; /*---Do-math-with-arrays-----------------------------------*/ for(i=0;i