Question: We have to code a program in C that sort a list by alphabetical order and use pointers.... we have this but it's not working

We have to code a program in C that sort a list by alphabetical order and use pointers.... we have this but it's not working and didn't know why, please help.

- We didn't know how to fill the str with the first letters. - The sort it's not working because of pointer error.

This is the code:

void sort(const char* arr[], int n) { qsort(arr, n, sizeof(const char*), myCompare); }

void lsOneParam(struct dirent *de, DIR *dr){ struct stat fileData; int index = 0; int i = 0; char * str = calloc(10, sizeof(char *)); while ((de = readdir(dr)) != NULL){ printf("%s ", de->d_name); index++; printf("%d ", index); } index--; strcpy(str, de->d_name); printf(str); //sort(str, index); for(i; i < index; i++){ printf("%s ", &str); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!