Maybe it just gets on my nerves that I have to run two complete programs simply to count the number of files in a directory (ls | wc -l), which seems like several orders of magnitude more cycles than was really needed.
#include <dirent.h>
DIR *d;
int n;
int main(int c, char *v[])
{
if (v[1]) d = opendir(v[1]);
if (d) while (readdir(d)) ++n;
return n;
}