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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started