Bonjour,
pourquoi si je fais
le fichier toto.txt ne se crée pas mais si je faisCode:
1
2
3 remove("toto.txt"); fopen("toto.txt","w+");
alors il se crée ?Code:
1
2
3 remove("toto.txt"); fopen("toto.txt","a+");
Merci
Version imprimable
Bonjour,
pourquoi si je fais
le fichier toto.txt ne se crée pas mais si je faisCode:
1
2
3 remove("toto.txt"); fopen("toto.txt","w+");
alors il se crée ?Code:
1
2
3 remove("toto.txt"); fopen("toto.txt","a+");
Merci
Je ne reproduis pas avec ceci:Exemple minimal et complet pour reproduire le problème SVP.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <stdlib.h> #include <stdio.h> int main(int argc, char** argv) { if (argc != 2) { fprintf(stderr, "Need fopen second argument\n"); return 1; } if (remove("toto.txt") != 0) { perror("remove failed"); } FILE* f = fopen("toto.txt", argv[1]); if (f == NULL) { perror("fopen failed"); } else if (fclose(f) != 0) { perror("fclose failed"); } }
effectivement, j'ai fait un exemple tout bête qui marche bien...
Mon pb ne vient donc pas de là.Code:
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
36
37 #include<stdlib.h> #include<stdio.h> #include<string.h> #include <errno.h> #define FOPENERROR fprintf( stderr, "%s %d: fopen() failed (%s)\n",__FILE__, __LINE__, strerror( errno )) int main() { remove("toto.txt"); FILE * pfile=fopen("toto.txt","a+"); if(pfile==NULL) { FOPENERROR; return(EXIT_FAILURE); } fprintf(pfile,"%d\t%d\n",2,3); fclose(pfile); pfile=fopen("toto.txt","a+"); if(pfile==NULL) { FOPENERROR; return(EXIT_FAILURE); } fprintf(pfile,"%d\t%d\n",4,5); fclose(pfile); return EXIT_FAILURE; }
Je fais de la programmation parallèle avec MPI et ce que je ne comprends pas, c'est qu'un coup mon fichier toto.txt est créé mais un autre coup il n'est pas créé. Je n'y comprends vraiment rien.
OK j'ai trouvé, je faisais un remove sur tous mes noeuds donc forcément le fichier n'était pas créé.
Je suis rassuré.