Bonjour,

Je code en C de temps en temps et aparament j'ai qq lacunes.
J'ai développé un pg qui liste certains fichiers dans conversion.bat (bat qui sera exécuté ensuite) d'une part.
D'autre part ces fichiers sont listés dans un tableau mots pour mémoire. puis quand conversion.bat sera terminé je lis "mots" et je supprime tous les fichiers contenu dans "mots".
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
	#define MAXMOTS 10
	#define MAXCARS 160
	char espace[MAXCARS];
	char *libre = espace;
	char *mots[MAXMOTS];
	char *fic;
	int nb_mots = 0;
	size_t n;
	int i=0;
	int j=0;
 
	FILE *fichier;
	FILE *work;
	int SIZE = 18;
	int fintrait = 0;
	int interval = 0;
	char chaine[22] = "Call ";
 
		if (system("dir /b pdf*.cmd > conversion.bat") == 0)
			{
				/* Ouverture du fichier pdf.cmd */
 
				if ((fichier = fopen("conversion.bat","r")) == NULL) 
				{
					fprintf(stderr,"\nErreur a l'ouverture du fichier conversion.bat\n");
					exit(1);
				}
 
				/* Ouverture d'un fichier de travail*/
 
				if ((work = fopen("work.txt","wb")) == NULL)
				{
					fprintf(stderr,"\nErreur de création d'un work fichier\n");
					fclose(fichier);
					free(fichier);
					exit(1);
				}
 
				/* Lecture du fichier conversion.bat */
				while (fgets(libre,SIZE,fichier) != NULL)
				{
					strcat(chaine,libre);
					mots[nb_mots]=libre;
					libre += strlen(libre) + 1;
					printf("%s - %d\n",mots[nb_mots],strlen(mots[nb_mots]));
 
					if (fprintf(work,"%s\n",chaine) < 0)
					{
						fprintf(stderr,"\nErreur ecriture dans le fichier work\n");
						fclose(fichier);
						fclose(work);
						free(fichier);
						free(work);
						exit(1);
					}
					strcpy(chaine,"Call ");
					nb_mots++;
				}
				for(i=0;i<nb_mots;i++)
				{
 
					if ((fic = (char *)malloc(strlen(mots[i])-1)) == NULL)
					{
						printf("\n Il y a un probleme d'allocation mémoire\n");
						exit(1);
					}
					printf("%d",strlen(mots[i])-1);
					strncpy(fic,mots[i],strlen(mots[i])-1);
					printf("%s\n",fic);
					remove(fic);
					free(fic);
				}
Le pb c'est que "fic" contient des caractères supplémentaires. Je n'ai pas réussit à ne copier que ex : "toto.cmd" mais "toto.cmdF" malgré l'allocation de la longueur exacte de chaque "mots[]".

Auriez-vous une idée ?
Merci