-
-
Save MRsoymilk/471263c7186a8d859635aa5670deb6a1 to your computer and use it in GitHub Desktop.
C useful code
This file contains hidden or 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 <dirent.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(int argc, char *argv[]){ | |
| DIR *dp; | |
| struct dirent *dirp; | |
| if(argc!=2){ | |
| printf("error: ls directory_name\n"); | |
| exit(-1); | |
| } | |
| if((dp = opendir(argv[1])) == NULL){ | |
| printf("error: can not open %s\n", argv[1]); | |
| exit(-1); | |
| } | |
| while((dirp = readdir(dp)) != NULL){ | |
| printf("%s\n", dirp->d_name); | |
| } | |
| closedir(dp); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment