Salut,

J'essaie de réaliser un programme sous Linux en C qui permet de parcourir un dossier passé en argument et afficher les fichiers contenu sur ce dossier ainsi faire le même travail si dossier trouvant sur le dossier passé en argument, je veux donner a chaque processus crée de parcourir un dossier et afficher les fichiers qu'il contient: j'ai essayé ce programme mais ca marche pas:

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
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
//#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
 
int main(int argc,char **argv){
	DIR *repertoire;
	char nnam[50],nnam2[50];
	struct stat *buff;
	struct dirent *fich;
	int i=1,j=0,*k; 
	if(argc!=2){
		printf("erreur123\n");
		exit(0);
		}
	stat(argv[1],buff);
	if(S_ISREG(buff->st_mode)!=0){
		printf("L'argument passé est un fichier\n");
		exit(1);
		}
	if(S_ISDIR(buff->st_mode)==0){
		printf("erreur ni fichier ni dosier\n");
		exit(2);
		}
	strcpy(nnam,argv[1]);
	strcpy(nnam2,argv[1]);
	repertoire=opendir(argv[1]);
	printf("c un dosier de chemin:%s\n",nnam);
	//fich=readdir(repertoire);//test
	//printf("nom fichier:  %s\n",fich->d_name);//test
	while((fich=readdir(repertoire))!=NULL){
 
		strcat(nnam,"/");
		printf("ca marche\n");
		strcat(nnam,fich->d_name);
		if(S_ISREG(buff->st_mode)!=0) { //si c'est un fichier 
			printf("le fichier: %s se trouve dans le repertoire",fich->d_name);
			strcat(nnam,nnam2);//annuler la concatenation
			}
		if(S_ISDIR(buff->st_mode)!=0){  //si c'est un repertoire
			if(fork()==0){
				//strcat(repertoire,"/");
				//strcat(repertoire,fich->name);
				//*repertoire=fiche->name;
				repertoire=opendir(nnam);
				printf("je suis dans le repertoire %s\n",nnam);
				strcpy(nnam2,nnam);
				i++;
				}
			else{
				while((j=wait(k))==-1)
					sleep(1);// attend la fin de processus fils
				}
		}
		}
	closedir(repertoire);
	printf("Fin\n");
	return 0;
}

SVP aidez moi :(:?