you don't need sortCompare(), nor do you need the typcasting. The second parameter should be the number of valid entries in the array, not the maximum number of entries.
Code:
qsort(theArray, z, y, strcmp);
I think file names can contain more than one period and can start with a period, so checking for "." and ".." will not work by checking the first character of the filename.
Code:
// check if d_name is a directory
if (strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name,"..") != 0) ){
The above is no guarentee that the file is not a directory. You also need to call stat() to get the file's attributes.
Code:
}
else{
strcpy(theArray[z], dir->d_name);
z++;
}
what is the above supposed to do? As written, it has no affect unless readdir() fails, and in that case the above code is invalid because dir will not be a valid pointer. I think you have that code in the wrong spot.
The last loop needs a different loop counter so that it can use z. Again, the loop should print only the first z number of valid strings.
Code:
for (i = 0; i < z;i++)
printf("%d: %s\n", i, theArray[i]);