#include #include #include // Grab the file extension of the filename passed. // TODO: current just does it until the first. Add in variations to grab all, // only specific entries like .tar.gz, etc. void usage(void) { printf("fex: returns the extension of the filename passed\n"); exit(0); } int main(int argc, char **argv) { if (argc <= 1) usage(); const char *file = argv[1]; // FIXME: unsafe. size_t len = strlen(file); if (len == 0) fprintf(stderr, "length of file cannot be zero\n"), exit(-1); for (len--; len != 0; len--) { if (file[len] == '.') { printf("%s\n", file + len + 1); return 0; } } return 0; }