Created
February 19, 2017 09:41
-
-
Save dattaz/a7d9b1932b18e3a5378e0c1361d7ffaf to your computer and use it in GitHub Desktop.
Count number of file in your current path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/types.h> | |
#include <dirent.h> | |
int main (void){ | |
DIR *dp; | |
dp = opendir ("./"); | |
int i=0; | |
if (dp != NULL){ | |
while (readdir (dp)){ | |
i++; | |
} | |
closedir (dp); | |
printf("%d\n",i-2); | |
} | |
else{ | |
perror ("Couldn't open the directory"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment