CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   PlZ help debugging this simple code (http://www.cfd-online.com/Forums/fluent-udf/68929-plz-help-debugging-simple-code.html)

Jinfeng October 6, 2009 14:13

PlZ help debugging this simple code
 
Hi all,

This code is pretty simple. All it's trying to do is just to read data from a file (data.dat) and then print some data on the console window to make sure the data was read and stored in correctly.

#include"udf.h"
float rho[8]; //one-dimensional matrix for storing data//
DEFINE_ON_DEMAND(read_data)
{
int i;
int k=0;
FILE *ifp;
ifp=fopen(
"data.dat", "r");

for(i=1; i<=9; i++)
{
fscanf(ifp,
"%f", rho[k]);
k++;
}
fclose(ifp);

printf(
"rho[1]= %f\n" , rho[1]);
printf(
"rho[5]= %f\n" , rho[5]);
printf(
"rho[8]= %f\n" , rho[8]);
}

I can interpret the code with no problem, but when I tried to excute it, it gave me this:

FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.

2. Save cas/data under new name.
3. Exit programme and restart to continue.
4. Report error to your distributor.
Error Object: ()

Does anybody know what the problem could be? Any help would be appreciated! Thanks.

Jinfeng

Jinfeng October 6, 2009 18:15

Never Mind! I think I found the problem. It should be

fscanf(ifp, "%f", &rho[k]);

Lesson: Small things can cause big trouble.


All times are GMT -4. The time now is 19:21.