Skip to content

Instantly share code, notes, and snippets.

@evanlong
Created January 25, 2012 06:39
Show Gist options
  • Save evanlong/1675102 to your computer and use it in GitHub Desktop.
Save evanlong/1675102 to your computer and use it in GitHub Desktop.
C Program to print current directories filesnames and lengths
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
int main(int argc, char** argv) {
DIR *d = opendir(".");
struct dirent *entry = NULL;
while(entry = readdir(d)) {
printf("%d %s\n", strlen(entry->d_name), entry->d_name);
}
closedir(d);
return 0;
}
// OS X version
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
int main(int argc, char** argv) {
DIR *d = opendir(".");
struct dirent *entry = NULL;
while(entry = readdir(d)) {
printf("%d %s\n", entry->d_namlen, entry->d_name);
}
closedir(d);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment