Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
double Tovn1(double Tovn, double prewatt, double maalt)
{
double P_k;
double P_s;
double R_th = 30;
double C_th = 22.5;
double A = 0.0025;
FILE *out1;
out1=fopen("1output.txt","w");
//double Tovn;
//double prewatt = 10018.50/1000;
P_k=(1/R_th)*(maalt-23);
P_s=A*0.0000000567*(pow((maalt)+273,4.0)-pow(23+273,4.0));
Tovn=maalt+(1/C_th)*(prewatt-P_k-P_s);
printf("Tovn: %lf \t prewatt: %lf \t maalt: %lf \n", Tovn, prewatt, maalt);
//return 0;
}
void read(int b)
{
int j=0;
double i=0;
double maalt=23;
double prewatt=0;
double Tovn;
char buff[80];
double num1, num2, num3;
char watt[50];
char tempmaalt[50];
char taelle[10];
FILE *in,*out;
out=fopen("output.txt","w");
if((in=fopen("Temp.txt", "r")) == NULL)
{
printf("\nError opening file");
}
while(fgets(buff, sizeof(buff), in))
{
if (3 == sscanf(buff, "%lf %lf %lf", &num1, &num2, &num3))
{
sprintf(tempmaalt, "%.1f", num2*100);
sprintf(watt, "%.1f", num3*b);
sprintf(taelle, "%.1f", i*0.5);
j=0;
while(taelle[j]!='\0')
{
if(taelle[j]=='.')
taelle[j]=',';
++j;
}
j=0;
while(tempmaalt[j]!='\0')
{
if(tempmaalt[j]=='.')
tempmaalt[j]=',';
++j;
}
j=0;
while(watt[j]!='\0')
{
if(watt[j]=='.')
watt[j]=',';
++j;
}
printf("Tidsstempel[S]: %s \t Power[W]: %s \t Measured[C]: %s \t ", taelle, watt, tempmaalt);
fprintf(out, "Tidsstempel[S]: %s \t Power[W]: %s \t Measured[C]: %s \t ", taelle, watt, tempmaalt);
Tovn1(Tovn, prewatt, maalt);
printf("Simulated[C]: %lf \n", Tovn);
fprintf(out, "Simulated[C]: %lf \n", Tovn);
maalt = Tovn;
prewatt = num3;
i++;
}
}
fclose(in);
fclose(out);
}
void main()
{
int a, b;
printf("Skriv hvad du vil \n 1: Køre program \n 2: Hvis du vil ændre Volt konstanten \n");
fflush(stdout);
scanf("%d", &a);
if(a==1){
b=15;
read(b);
}
else{
printf("Skriv en Volt konstant: ");
fflush(stdout);
scanf("%d", &b);
read(b);
}
}
But I can't figure out how to make the doubles usable in other functions. Can anyone help me?