Hi i'm trying to read data from and archive but, i couldnt, make it here is a sample of my input file (datai want to arrange), output file ( how do i wish my data get arrange), and code output ( how my code is arranging the data)
Code:
This is my INPUT DATA
ASCII 1
!File started at: 2008/11/12 13:35:17
Degrees of freedom:
temperature 1 :fs
Total DOFs: 1
Number Of Nodes: 25
Time: 1 1 0.300000000000E-001
temperature
Perm: 25 25
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
10.000000000000000
11.000000000000000
12.000000000000000
13.000000000000000
14.000000000000000
15.199954991339460
16.199954991339780
17.199954991338899
18.199954991340981
19.199954991341123
20.370656679269594
21.370656679269800
22.370656679274532
23.370656679277445
24.370656679280167
25.512291425849234
26.512291425852432
27.512291425862628
28.512291425872711
29.512291425879688
30.631400793908682
31.631400793907517
32.631400793922090
33.631400793933246
34.631400793944735
Time: 2 2 0.600000000000E-001
temperature
Perm: 25 25
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20
21 21
22 22
23 23
24 24
25 25
35.000000000000000
36.000000000000000
37.000000000000000
38.000000000000000
39.000000000000000
40.157362005216520
41.157362005217102
42.157362005220897
43.157362005221138
44.157362005235335
45.312981987533192
46.312981987503875
47.312981987483582
48.312981987425133
49.312981987428635
50.466161946464986
51.466161946399644
52.466161946295564
53.466161946179312
54.466161946121098
55.617384755971983
56.617384755900851
57.617384755696456
58.617384755566832
59.617384755436980
Code:
This is how do i want my ouptut look alike
1 1 10.000000000000000 35.000000000000000
2 2 11.000000000000000 36.000000000000000
3 3 12.000000000000000 37.000000000000000
4 4 13.000000000000000 38.000000000000000
5 5 14.000000000000000 39.000000000000000
6 6 15.199954991339460 40.157362005216520
7 7 16.199954991339780 41.157362005217102
8 8 17.199954991338899 42.157362005220897
9 9 18.199954991340981 43.157362005221138
10 10 19.199954991341123 44.157362005235335
11 11 20.370656679269594 45.312981987533192
12 12 21.370656679269800 46.312981987503875
13 13 22.370656679274532 47.312981987483582
14 14 23.370656679277445 48.312981987425133
15 15 24.370656679280167 49.312981987428635
16 16 25.512291425849234 50.466161946464986
17 17 26.512291425852432 51.466161946399644
18 18 27.512291425862628 52.466161946295564
19 19 28.512291425872711 53.466161946179312
20 20 29.512291425879688 54.466161946121098
21 21 48.312981987425133 55.617384755971983
22 22 49.312981987428635 56.617384755900851
23 23 50.466161946464986 57.617384755696456
24 24 51.466161946399644 58.617384755566832
25 25 52.466161946295564 59.617384755436980
Code:
This the my program output
1 1 10.000000000000000 35.000000000000000
2 2 11.000000000000000 36.000000000000000
3 3 12.000000000000000 37.000000000000000
4 4 13.000000000000000 38.000000000000000
5 5 14.000000000000000 39.000000000000000
6 6 15.199954991339460 40.157362005216520
7 7 16.199954991339780 41.157362005217102
8 8 17.199954991338899 42.157362005220897
9 9 18.199954991340981 43.157362005221138
10 10 19.199954991341123 44.157362005235335
11 11 20.370656679269594 45.312981987533192
12 12 21.370656679269800 46.312981987503875
13 13 22.370656679274532 47.312981987483582
14 14 23.370656679277445 48.312981987425133
15 15 24.370656679280167 49.312981987428635
16 16 25.512291425849234 50.466161946464986
17 17 26.512291425852432 51.466161946399644
18 18 27.512291425862628 52.466161946295564
19 19 28.512291425872711 53.466161946179312
20 20 29.512291425879688 54.466161946121098
21 21 9277445 48.312981987425133 55.617384755971983
15 15 24.370656679280167 49.312981987428635 56.617384755900851
16 16 25.512291425849234 50.466161946464986 57.617384755696456
17 17 26.512291425852432 51.466161946399644 58.617384755566832
18 18 27.512291425862628 52.466161946295564 59.617384755436980
As you may see, everything seems to be going fine until 21 21 is reached, the first numbers of the second column 9277445 are the last numbers of the second column (line14) , on line 21 the fourth and fifth column are the data that should be on line 22, but somehow 9277445 appear on my data, after 21 the count get lost, and start with 15 instead of 22, 16 instead of 23 and so on...., but the fourth ant five columns are the data that should be on each line.
Code:
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<ctype.h>
#include<io.h>
FILE *fp;
FILE *fpx;
FILE *fpdatos;
FILE *fpdatosr;
fpos_t pos;
char *p ;
char *q;
char var1[30];
char cadena[4096];
char vacia[4096];
char cad[4096];
char *str2="Perm: ";
char *str1="Number Of Nodes:";
int flag=0,i=0,perm=0,fin=0,aux=0,j,hand,cont=0,n;
main()
{ //fpos=fopen("posiciones.txt","w");
fpx=fopen("nuevo.result","r");
fp=fopen("nuevo.result", "r");
fpdatos=fopen("salida.txt","w");
fpdatosr=fopen("salida.txt","r");
n=2;
if(fp == NULL)
{clrscr();
printf("\n Error Archivo no encontrado");
getch();
return 1;
}
else
{ while(fin!=1)
//while(eof)
{ //i++;
do
{
fgets(cadena, 4096, fp);
fgets(cad, 4096,fpx);
p=strstr(cadena,str1);
if(p != NULL) // Determinación Número de Nodos
{ printf("\n %s",cadena);
strcpy(var1,&(p[strlen(p)-4]));
perm=atoi(var1); //Asigna No. de Nodos a perm
}
p=strstr(cadena,str2); //Ubica La cadena Perm:
if(p !=NULL) //Para empezar a leer datos y escribirlos
{
while(i<perm)
{ fgets(cad,4096,fpx);
i++;
}
flag=1;
i=0;
}
if(flag!=0) Here on is where i read data and assign them to the correct line
{ do
{
if(!aux)
{//cadena[0]='\0';
memset(cadena,'\0',4096);
memset(cad,'\0',4096);
fgetpos(fp, &pos);
q=fgets(cadena, 4096, fp);
fgetpos(fp, &pos); //Lectura de Archivo y escritura
q[strlen(q)-1]='\0';
p=fgets(cad,4096,fpx);
fputs(q,fpdatos);
fputs(p,fpdatos);
strcpy(q,"");
strcpy(p,"");
i++;
}
else
{
memset(cadena,'\0',4096);
memset(cad,'\0',4096);
fgetpos(fpdatosr, &pos);
q=fgets(cadena, 4096, fpdatosr);
fgetpos(fpdatosr, &pos);
q[strlen(q)-1]='\0';
p=fgets(cad,4096,fpx);
fputs(q,fpdatos);
fputs(p,fpdatos);
strcpy(q,"");
strcpy(p,"");
i++;
}
}
while((perm) >i);
i=0;
while(i<perm)
{fgets(cadena,4096,fp);
i++;
}
aux=1;
i=0;
flag=0;
cont++;
rewind(fpdatos);
rewind(fpdatosr);
}
}while(cont<n);
fin=1;
}
}
fclose(fpx);
fclose(fp);
fclose(fpdatos);
fclose(fpdatosr);
}
I know i'm asking for too much, maybe someone have experimented something like me, any sugestion would be very helpful.
Why my program keeps doing it correctly until 21 is reached.
As you may see i clear data twice on the same routine just to make sure undesired data appear.
In Advance Thank you very much!!!!