/* file18 prints a list of files in the current directory, one name per line. file18 omits file names starting with dots, because users normally don't want to see files with those names. It also omits file names that contain newlines, because those names would confuse the line-by-line output format. This program uses DIR, dirent, opendir(), and readdir(), which will not appear on the tests in this course. It also uses ->, which will be covered after midterm 2. file18 is similar to the standard UNIX ls program, but the output of file18 is not in order. Try file18 | sort to print the output in order; sort is another standard UNIX program. This is still not quite the same as what ls prints; try writing a program that reads lines such as file2.c file3.c file4.c file5.c file6.c and prints them in columns as file2.c file5.c file3.c file6.c file4.c the way that ls does. */ #include #include #include #include #include void die(void) { fprintf(stderr,"fatal: unable to read current directory: %s\n",strerror(errno)); exit(111); } int main(void) { DIR *d; struct dirent *e; d = opendir("."); if (!d) die(); for (;;) { errno = 0; e = readdir(d); if (!e) { if (errno) die(); exit(0); } if (e->d_name[0] != '.') if (!strchr(e->d_name,'\n')) printf("%s\n",e->d_name); } }