Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Explain why talent management is important.

Answered: 1 week ago

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago