small problem in FILE HANDLING / FILE MANAGMENT

[b][red]This message was edited by devesh.baghel at 2007-4-4 0:42:47[/red][/b][hr]
hi guys i m using Dev-C++ Compiler........

i m putting down my problem here as follows........

#include
#include
#include

#define ni 10
#define nj 9

int i,j;
float dx1,dx2,x[2][nj][ni];
double fgrid11();

FILE *coord;

main()
{
fgrid11();
fclose(coord);
getch();

}

double fgrid11()
{
coord=fopen("Co-Ordinates.txt","w");

dx1=(6.0/6);
x[0][0][0]=-dx1;

dx2=(7.0/7);
x[1][0][0]=-dx2;

for(i=0;i<=7;i++)
{
for(j=0;j<=8;j++)
{
x[0][j][i]=x[0][0][0]+(dx1*i);
x[1][j][i]=x[1][0][0]+(dx2*j);
fprintf(coord,"%lf %lf
",x[0][j][i],x[1][j][i]);
// printf("%f %f
",x[0][j][i],x[1][j][i]);
}
return;
}

" Now i want to use these values stored in x[0][j][i] & x[1][j][i].........in new programme.....as follows.....


#include<stdio.h>
#include
#include

#define ni 10
#define nj 9
#define ncelli ni-1
#define ncellj nj-1
int i,j;
float dx1,dx2,x[2][nj][ni],xcell[2][Ncelli][Ncellj];
double grid;

FILE *coord,*fgrid;


main()
{
grid();
fclose(fgrid);
getch();

}

double grid()
{

gama=1.0/(re);

nmax=(ncelli)*(ncellj);

coord=fopen("Co-Ordinates.txt","r");
fgrid=fopen("final-grid.txt","w");


for(i=1;i<=ncelli-2;++i)
{
for(j=1;j<=ncellj-2;++j)
{
xcell[0][j][i]= 0.5*(x[0][j][i]+x[0][j][i+1]);
xcell[1][j][i]= 0.5*(x[1][j][i]+x[0][j+1][i]);

printf("%3.5f %3.5f
",xcell[0][j][i],xcell[1][j][i]);
}
}
return;
}


" IN 2ND PROGRAMME I WANT TO USE VALUES OF X[0][J][I] FOR CALCULATION OF XCELL[0][J][I] & XCELL[1][J][I]..............
BUT I AM NOT GETTING THE VALUES...............

PLZ GIVE THE CORRECT SOLUTION.........

thank you so much for previous reply........but i dint get the exact solution.....so plz give me the solution in same format........

thank you all



Comments

  • : hi guys i m using Dev-C++ Compiler........
    :
    : i m putting down my problem here as follows........
    :
    : #include
    : #include
    : #include
    :
    : #define ni 10
    : #define nj 9
    :
    : int i,j;
    : float dx1,dx2,x[2][nj][ni];
    : double fgrid11();
    :
    : FILE *coord;
    :
    : main()
    : {
    : fgrid11();
    : fclose(coord);
    : getch();
    :
    : }
    :
    : double fgrid11()
    : {
    : coord=fopen("Co-Ordinates.txt","w");
    :
    : dx1=(6.0/6);
    : x[0][0][0]=-dx1;
    :
    : dx2=(7.0/7);
    : x[1][0][0]=-dx2;
    :
    : for(i=0;i<=7;i++)
    : {
    : for(j=0;j<=8;j++)
    : {
    : x[0][j][i]=x[0][0][0]+(dx1*i);
    : x[1][j][i]=x[1][0][0]+(dx2*j);
    : fprintf(coord,"%lf %lf
    ",x[0][j][i],x[1][j][i]);
    : // printf("%f %f
    ",x[0][j][i],x[1][j][i]);
    : }
    : return;
    : }
    :
    : " Now i want to use these values stored in x[0][j][i] & x[1][j][i].........in new programme.....as follows.....
    :
    :
    : #include<stdio.h>
    : #include
    : #include
    :
    : #define ni 10
    : #define nj 9
    : #define ncelli ni-1
    : #define ncellj nj-1
    : int i,j;
    : float dx1,dx2,x[2][nj][ni],xcell[2][Ncelli][Ncellj];
    : double grid;
    :
    : FILE *coord,*fgrid;
    :
    :
    : main()
    : {
    : grid();
    : fclose(fgrid);
    : getch();
    :
    : }
    :
    : double grid()
    : {
    :
    : gama=1.0/(re);
    :
    : nmax=(ncelli)*(ncellj);
    :
    : coord=fopen("Co-Ordinates.txt","r");
    : fgrid=fopen("final-grid.txt","w");
    :
    :
    : for(i=1;i<=ncelli-2;++i)
    : {
    : for(j=1;j<=ncellj-2;++j)
    : {
    : xcell[0][j][i]= 0.5*(x[0][j][i]+x[0][j][i+1]);
    : xcell[1][j][i]= 0.5*(x[1][j][i]+x[0][j+1][i]);
    :
    : printf("%3.5f %3.5f
    ",xcell[0][j][i],xcell[1][j][i]);
    : }
    : }
    : return;
    : }
    :
    :
    : " IN 2ND PROGRAMME I WANT TO USE VALUES OF X[0][J][I] FOR CALCULATION OF XCELL[0][J][I] & XCELL[1][J][I]..............
    : BUT I AM NOT GETTING THE VALUES...............
    :
    : PLZ GIVE THE CORRECT SOLUTION.........
    :
    :


    Looking at your code, it seems like you did not read in the values saved in "Co-Ordinates.txt".

    All you did was open the file for reading but you never read any values.

    I think you are missing the 'fscanf' function in this loop.

    for(i=1;i<=ncelli-2;++i)
    {
    for(j=1;j<=ncellj-2;++j)
    {
    xcell[0][j][i]= 0.5*(x[0][j][i]+x[0][j][i+1]);
    xcell[1][j][i]= 0.5*(x[1][j][i]+x[0][j+1][i]);

    printf("%3.5f %3.5f
    ",xcell[0][j][i],xcell[1][j][i]);
    }
    }

    Have a closer look at it. Also dont forget 'fclose(coord)' in main.

    loco
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion