Hey all. New problem. Been working on this one though during TA hours. Here's the problem (#1):

http://ece.arizona.edu/~ece175/assig...signment06.pdf

Ignore #2. I have a separate thread for that one.

Now here's my program:

My problem is, I messed up the formatting somewhere it seems. It compiles fine and runs almost as it should. But here's what my roots.txt looks like after the program has run:Code:#include <stdio.h> #include <math.h> #define INFILE "input_equations.txt" #define OUTFILE "roots.txt" int compute_roots(float x2,float x,float term,double *root1,double *root2) { float t1; t1=x*x-4*x2*term; if (t1<0) return 0; else if (t1==0) *root1=*root2=-1*x/(2*x2); else { *root1=(-1*x+sqrt(t1))/(2*x2); *root2=(-1*x-sqrt(t1))/(2*x2); } return 1; } int main(int argc, char* argv[]) { float a,b,c; double r1,r2; FILE *ifp,*ofp; if ((ifp=fopen(INFILE,"r"))!=NULL) { ofp=fopen(OUTFILE,"w"); while (!feof(ifp)) { fscanf(ifp,"%f %f %f",&a,&b,&c); if (compute_roots(a,b,c,&r1,&r2)) fprintf(ofp,"%g %g %g root1=%g root2=%g\n",a,b,c,r1,r2); else fprintf(ofp,"%g %g %g The roots are complex\n",a,b,c); } fclose(ifp); fclose(ofp); } else puts("ERROR:FILE NOT FOUND"); return 0; }

1 -3 2 root1=2 root2=1

1 0 -4.84 root1=2.2 root2=-2.2

1 0 1 The roots are complex

1 0 1 The roots are complex

Not only is the spacing not organized as it should be, but the 1 0 1 line is recorded into the file twice, thus two "The roots are complex" lines...

Can someone please help me!