Skip to content

Instantly share code, notes, and snippets.

@MRsoymilk
Created September 5, 2020 03:44
Show Gist options
  • Select an option

  • Save MRsoymilk/471263c7186a8d859635aa5670deb6a1 to your computer and use it in GitHub Desktop.

Select an option

Save MRsoymilk/471263c7186a8d859635aa5670deb6a1 to your computer and use it in GitHub Desktop.
C useful code
#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