well i changed this
Code:
// Generally file opens are done as below
if ((outfile=fopen("myoutput.txt","w+t"))==NULL)
{
printf("Error opening myoutput.txt\n");
exit(0);
// read the three values
// its a good idea to account for \n's in the file
fscanf(infile,"%d\n",&x);
fscanf(infile,"%d\n",&y);
fscanf(infile,"%d\n",&z);
// sum and avg
sum = x+y+z;
avg = (float)sum/3.0;
// print out values
fprintf(outfile,"Values: %d, %d, %d\n",x,y,z);
fprintf(outfile,"Sum: %d\n",sum);
fprintf(outfile,"Avg: %7.2f\n",avg);
// close the files
fclose(infile);
fclose(outfile);
}
}
to this and it works fine now...
Code:
// Generally file opens are done as below
if ((outfile=fopen("myoutput.txt","w+t"))==NULL)
{
printf("Error opening myoutput.txt\n");
exit(0);
}
// read the three values
// its a good idea to account for \n's in the file
fscanf(infile,"%d\n",&x);
fscanf(infile,"%d\n",&y);
fscanf(infile,"%d\n",&z);
// sum and avg
sum = x+y+z;
avg = (float)sum/3.0;
// print out values
fprintf(outfile,"Values: %d, %d, %d\n",x,y,z);
fprintf(outfile,"Sum: %d\n",sum);
fprintf(outfile,"Avg: %7.2f\n",avg);
// close the files
fclose(infile);
fclose(outfile);
}