Created
January 25, 2012 06:39
-
-
Save evanlong/1675102 to your computer and use it in GitHub Desktop.
C Program to print current directories filesnames and lengths
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 <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; | |
} |
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
// 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