Hello guys..!
What i try to do is to write a code which reads some specific values from a file and stores them in an array. My File looks like this
What i want to do is read the values below the columns apha cl cd and store them into the arrays alpha[],cl[],cd[]. What i have achieved so far is to do this for a variable but not for an array. Also the code below just reads the first line and doesn't go any further. Can you please help me to modify the code...?Code:XFOIL Version 6.96 Calculated polar for: Myfoil 1 1 Reynolds number fixed Mach number fixed xtrf = 1.000 (top) 1.000 (bottom) Mach = 0.000 Re = 0.200 e 6 Ncrit = 4.000 alpha CL CD CDp CM Top_Xtr Bot_Xtr ------ -------- --------- --------- -------- -------- -------- -5.000 -0.3878 0.06508 0.06153 -0.0244 1.0000 0.0121 -4.000 -0.2482 0.05038 0.04638 -0.0478 0.9968 0.0186 -3.000 -0.1148 0.03410 0.02946 -0.0643 0.9903 0.0224 -2.000 0.0165 0.02408 0.01845 -0.0718 0.9834 0.0379 -1.000 0.1420 0.01608 0.00891 -0.0717 0.9759 0.0098 0.000 0.2613 0.01247 0.00479 -0.0724 0.9650 0.0092 1.000 0.4559 0.01317 0.00250 -0.0897 0.0119 0.2606 2.000 0.5898 0.01434 0.00545 -0.0948 0.0102 1.0000 3.000 0.6859 0.01915 0.01044 -0.0906 0.0063 1.0000 4.000 0.7850 0.02724 0.01952 -0.0854 0.0063 1.0000 -5.000 -0.1247 0.00000 -0.00040 -0.0964 0.0000 0.0000 -4.000 -0.0067 0.00000 -0.00036 -0.0970 0.0000 0.0000 -3.000 0.1112 0.00000 -0.00033 -0.0975 0.0000 0.0000 -2.000 0.2291 0.00000 -0.00031 -0.0982 0.0000 0.0000 -1.000 0.3470 0.00000 -0.00028 -0.0988 0.0000 0.0000 0.000 0.4647 0.00000 -0.00027 -0.0995 0.0000 0.0000 1.000 0.5823 0.00000 -0.00025 -0.1002 0.0000 0.0000 2.000 0.6997 0.00000 -0.00024 -0.1010 0.0000 0.0000 3.000 0.8169 0.00000 -0.00024 -0.1017 0.0000 0.0000 4.000 0.9339 0.00000 -0.00024 -0.1025 0.0000 0.0000 5.000 1.0506 0.00000 -0.00024 -0.1034 0.0000 0.0000 6.000 1.1669 0.00000 -0.00025 -0.1042 0.0000 0.0000 7.000 1.2829 0.00000 -0.00027 -0.1051 0.0000 0.0000 8.000 1.3985 0.00000 -0.00029 -0.1060 0.0000 0.0000 9.000 1.5136 0.00000 -0.00031 -0.1069 0.0000 0.0000
Thank you..!Code:double FileRead() { double n,cl,cd,result; char target[10]={"---"}; char buff[2000]={""}; char *ps; FILE *fp=fopen("save.txt", "r"); if(!fp) { printf("Error opening file!\n"); return 0; } while((fgets(buff, sizeof(buff), fp))!=NULL) { ps=strstr(buff,target); if(ps) { fgets(buff,sizeof(buff),fp); sscanf(buff, "%lf %lf %lf",&n,&cl,&cd); printf("cl: %f cd: %f\n",cl,cd); break; } } result = cl/cd; if(result > 300) { result = 0.0; printf("Could not get result\n"); } printf("The result is %1.2f\n",result); fclose(fp); return result; return 0; }