[ prog / sol / mona ]

prog


Scsh - the Scheme Shell

10 2022-08-06 23:51 *

>>1

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;
}
15


VIP:

do not edit these