Sorting Directory Entries

Sorting Directory Entries - // Check if name matches if

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sorting Directory Entries Shells like /bin/sh sort the entries matched by a wildcard. For example “echo *” will list all the entries in the current directory sorted. You will have to modify the wildcard matching as follows:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sorting Directory Entries struct dirent * ent; int maxEntries = 20; int nEntries = 0; char ** array = (char**) malloc(maxEntries*sizeof(char*)); while ( (ent = readdir(dir))!= NULL) {
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Check if name matches if (advance(ent->d_name, expbuf) ) { if (nEntries == maxEntries) { maxEntries *=2; array = realloc(array, maxEntries*sizeof(char*)); assert(array!=NULL); } Sorting Directory Entries closedir(dir); sortArrayStrings(array, nEntries); // Add arguments for (int i = 0; i < nEntries; i++) { Command::_currentSimpleCommand-> insertArgument(array[i])); } free(array);...
View Full Document

Page1 / 3

Sorting Directory Entries - // Check if name matches if

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online