Bonjour, j'ai un prgm qui marche bien lorsque je n'ouvre que qq fichiers (avec fopen). Mon algo était le suivant :
1) j'ouvre tous mes fichiers
2) je calcule
3) j'écris sur le disque dur
4) je ferme mes fichiers
Malheureusement, maintenant je dois ouvrir plus de 1000 fichiers et là, j'ai une erreur qui me dit que j'ai trop de fichiers d'ouverts. Donc je décide de changer mon algo de la manière suivante :
1) je donne un nom à tous mes fichiers --> tableau NameFileOutput
2) je calcule
3) j'ouvre mon fichier i
4) j'écirs dans ce fichier
5) je ferme mon fichier i
6) je passe au fichier i+1 et ainsi de suite
Ainsi, je n'ai qu'un seul fichier d'ouvert à la fois.
Je dois avor un pb de pointeur car j'ai l'erreur suivante : fopen() failed (Bad address)
Voic mon code :
ici je donne un nom à tous mes fichies :
voici ma fonction pour écrire dans mes fichiers
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 char * NameFileOutput[N+3]; for(j=0;j<N;++j) { char s[]="Particle"; char buf[20]; /* convert the integer j+1 in string and put the string in buf */ sprintf(buf,"%u",j+1); strcat(s,buf); strcat(s,".txt"); NameFileOutput[j]=strdup(s); } NameFileOutput[N]="Mean.txt"; NameFileOutput[N+1]="Volumes.txt"; NameFileOutput[N+2]="RandomInitialConditions.txt";
Sauriez-vous me dire où se trouve mon pb d'adresse ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 void fPrintOutput(FILE ** file,realtype t,N_Vector * y,unsigned int N, Engine * e,Mechanism * mec,char * NameFileOutput[]) { blabla for(i=0;i<N;++i) { file[i]=fopen(NameFileOutput[i], "w+"); if(file[i]==NULL) <-- ici ca vaut NULL pour i == 0 { FOPENERROR; MPI_Finalize(); exit(EXIT_FAILURE); } insp1=i*nsp1; fprintf(file[i],"%14.6le\t%14.6le\t%14.6le",theta,P[i],T[i]); for(s=0;s<ns;++s) fprintf(file[i],"\t%14.6le",NV_Ith_S(y[i],s)); fprintf(file[i],"\n"); fclose(file[i]); } /* end of for(i=0;i<N;++i) */ file[N]=fopen(NameFileOutput[N], "w+"); if(file[N]==NULL) { FOPENERROR; MPI_Finalize(); exit(EXIT_FAILURE); } fprintf(file[N],"%14.6le\t%14.6le\t%14.6le",theta,Pmean,Tmean); for(s=0;s<ns;++s) fprintf(file[N],"\t%14.6le",smean[s]); fprintf(file[N],"\n"); fclose(file[N]); }
Merci.
Partager