Hi guys, this is my text file (Data.txt):
rho_0 10
kp_0 8
Beta_kp 6
x_min 5
x_max 8
y_min 9
y_max 5
z_min 4
z_max 7
I want to read from this text file line by line and store each Value in the parameter at the same line. for example, for the first line store 10 in rho_0. I have written as below.At the next end I want to use x_min and x_max ... to calculate Volume. I mean
Volume=(x_max-x_min)*(y_max-y_min)*(z_max-z_min)
I have written the code as below and it works with Code::Blocks but When I want to run it in Microsoft Visual Studio, it gives me these error as below :
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(63): error C2143: syntax error : missing ';' before 'type'
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(65): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(66): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(67): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(68): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(69): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(70): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(71): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(72): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(73): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(74): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(75): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(76): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(77): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(78): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(79): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(80): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(81): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(82): error C2065: 'storage' : undeclared identifier
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(84): error C2143: syntax error : missing ';' before 'type'
1>c:\users\documents\visual studio 2010\projects\funktion\funktion\main.c(86): error C2065: 's' : undeclared identifier
1>
1>Build FAILED.
Can some one please tell me, what is the problem?
This is also my code:
Code:#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { double rho_0, kp_0, Beta_kp; double x_min, x_max ,y_min ,y_max ,z_min, z_max, V_plasmazone; FILE *inputfile; /*char inputpath[100]; char path [100] ; strcpy(inputpath, path); strcat(inputpath, "Data.txt"); inputfile = fopen(inputpath, "r"); if(inputfile) { ScanCheck(fscanf(inputfile, "%s", inputpath), 1, inputfile, "Data.txt", 1); strcat(path, inputpath); strcat(path, "/"); } else { Error("Error opening input.txt - file!"); }*/ inputfile =fopen ("Data.txt","r") ; if(inputfile == NULL) { perror("Unable to open file!"); exit (1); } char storage[100]; fscanf(inputfile, "%s %lf\n", storage, &rho_0); printf("%s %lf\n", storage, rho_0); fscanf(inputfile, "%s %lf\n", storage, &kp_0); printf("%s %lf\n", storage, kp_0); fscanf(inputfile, "%s %lf\n", storage, &Beta_kp); printf("%s %lf\n", storage, Beta_kp); fscanf(inputfile, "%s %lf\n", storage, &x_min); printf("%s %lf\n", storage, x_min); fscanf(inputfile, "%s %lf\n", storage, &x_max); printf("%s %lf\n", storage, x_max) ; fscanf(inputfile, "%s %lf\n", storage, &y_min); printf("%s %lf\n", storage, y_min); fscanf(inputfile, "%s %lf\n", storage, &y_max); printf("%s %lf\n", storage, y_max); fscanf(inputfile, "%s %lf\n", storage, &z_min); printf("%s %lf\n", storage, z_min); fscanf(inputfile, "%s %lf\n", storage, &z_max); printf("%s %lf\n", storage, z_max); char s[100] = "V_plasmazone"; V_plasmazone = ( x_max - x_min )*( y_max - y_min )*( z_max - z_min ); printf( "%s %lf\n", s, V_plasmazone ); fclose(inputfile); return 0; }