pb avec la fonction readdir
Bonjour, j'ai un pb avec la fonction readdir. Je veux compter combien de sous-répertoire j'ai dans mon répertoire. Voici mon code :
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#include<math.h>
#include<sys/types.h>
#include<dirent.h>
#include <errno.h>
#include<ctype.h> /* in order to have the function isdigit() */
int main(int argc, char *argv[])
{
char mydir[]="Essai1Sigma2Phi10m2";
unsigned int col=3;
unsigned int i,j,count;
DIR * pDIR;
struct dirent * pDirEnt;
/* open the directory Essai1Sigma2Phi10m2
(to open the current directory, write pDIR=opendir("."); )
*/
pDIR = opendir(mydir);
if ( pDIR == NULL )
{
fprintf( stderr, "%s %d: opendir() failed (%s)\n",__FILE__, __LINE__, strerror( errno ));
exit(EXIT_FAILURE);
}
/* compute the numbers of sub-directories in the directory mydir */
unsigned int nbdir=0;
pDirEnt = readdir( pDIR );
while ( pDirEnt != NULL )
{
nbdir++;
printf("%s\t%d\n",pDirEnt->d_name,nbdir);
pDirEnt = readdir( pDIR );
}
printf("Fin du while\nnbdir = %d\n");
closedir(pDIR);
double nbpar[nbdir];
printf("nbdir = %d\n");
return EXIT_SUCCESS;
} |
et voici ma sortie :
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
|
. 1
.. 2
Part100 3
Part105 4
Part110 5
Part115 6
Part120 7
Part125 8
Part130 9
Part140 10
Part150 11
Part160 12
Part170 13
Part180 14
Part190 15
blabla
Part80 70
Part85 71
Part90 72
Part95 73
Homogene.txt 74 <-- ceci est un fichier et non un repertoire
Fin du while
nbdir = 5247048
nbdir = 5382144 |
Pourquoi ai-je les deux valeurs suivantes
Code:
1 2 3
|
nbdir = 5247048
nbdir = 5382144 |
Merci.