IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX INPUT: B C...

90.2K

Verified Solution

Question

Programming

IN PROGRAMMING LANGUAGE C

-I am trying to alphbetize a string in descending orto

EX

INPUT: B C D A

OUTPUT:

D

C

B

A

#include
#include
#include
#include

int main(int argc, char*argv[])
{


        int MAX = 100000;
        int i =0;
        int k =0;
        int j =0;
        char array[MAX];
        char split[] = \",.-!?()0123456789\";
        int n = 0;
        char second[MAX];
        printf(\"Please enter ina String: \");
        //String input
       fgets(array,MAX,stdin);

        char **first=(char**)malloc(sizeof(char*));
        char *token =strtok(array,split);

        while(token!=NULL)
        {

               k = strlen(token);
               first=(char **)realloc(first,(n+1)*sizeof(char));
               first[n] = (char *)malloc((k+1)*sizeof(char));
               memcpy(first[n],token,k*sizeof(char));
               token = strtok(NULL,split);
               n++;

        }

        second =sortedArray(first,n);
        for(i =0;i        {
        printf(\"%s\",second[i]);
        }


        return 0;

}

char *sortedArray(char *sortRay[], int size)
{
        int i =0;
        int j =0;
        char temp[300];
        for(i =0; i        {
          for(j =i +1;j          {
            if(strcmp(sortRay[i],sortRay[j])>0)
           {
            strcpy(temp,sortRay[i]);
            strcpy(sortRay[i],sortRay[j]);
            strcpy(sortRay[j],temp);
           }
          }
        }
        return sortRay;
}

Answer & Explanation Solved by verified expert
4.0 Ratings (757 Votes)
include include int main void int MAX 100000char    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students