Reading numbers from a text file[Help]
Hey i am an newbie when it comes to c programming..i am from mechanical stream and this piece of coding is useful for our final year project..the program runs fine but i just want it to read the inputs from a text file rather than user manually entering it! what changes should i make in the codes..any type of help would be appreciated :-)
Code:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
float friction,flow;
float project (float density,float v,float d,float length,float re,int n,float massflow,float inletpressure,float area,float velocity)
{
float exitpressure;
area=(3.1415785*d*length);
flow=(massflow/density);
velocity=(massflow/(density*area));
printf("The Velocity is %f\n",velocity);
re=((density*velocity*d)/v);
printf("The Reynold number is %f\n",re);
if(re<=2000)
{
friction=(64/re);
printf("Friction Factor Is %f\n",friction);
}
else
{
friction= 0.3164/(pow(re,.25));
printf("Friction Factor Is %f\n",friction);
}
exitpressure=inletpressure-((8*density*flow*flow*friction*length)/(3.1415785*3.1415785*d*d*d*d*d));
return exitpressure;
}
void main()
{
clrscr();
float deltap[100],density,v,d,length,massflow,re,exitpressure,inletpressure,area,velocity;
int n,i=1;
printf("Enter number of sections\n");
scanf("%d",&n);
if(i<=n)
{
printf("Enter The Mass Flow Rate\n");
scanf("%f",&massflow);
printf("Enter The 1st sec Diameter of The Pipe(metre)\n");
scanf("%f",&d);
printf("Enter The Density of Fluid(kg/m^3)\n");
scanf("%f",&density);
printf("Enter The viscosity\n");
scanf("%f",&v);
printf("Enter The 1st sec Length of The Pipe(metre)\n");
scanf("%f",&length);
printf("Enter The Inlet Pressure\n");
scanf("%f",&inletpressure);
exitpressure=project(density,v,d,length,re,n,massflow,inletpressure,area,velocity);
printf("The Friction Coefficient is %f\n",friction);
printf("The Volumetric Flow rate(Q) is %f m^3/s\n",flow);
printf("The Exit Pressure is %f\n",exitpressure);
deltap[i]=inletpressure-exitpressure;
i++;
}
while(i<=n)
{
inletpressure=exitpressure;
printf("Enter Diam of %d pipe\n",i);
scanf("%f",&d);
printf("Enter Length of %d pipe\n",i);
scanf("%f",&length);
exitpressure=project(density,v,d,length,re,n,massflow,inletpressure,area,velocity);
printf("The Friction Coefficient is %f\n",friction);
printf("The Volumetric Flow rate(Q) is %f m^3/s\n",flow);
printf("The Exit Pressure is %f\n",exitpressure);
deltap[i]=inletpressure-exitpressure;
i++;
}
printf("The Pressure Drop\n");
for(i=1;i<=n;i++)
printf("\n %d sec drop is %f",i,deltap[i]);
getch();
}