Sorts the array of strings by function call

Source: Internet
Author: User
Tags sorts

#include <stdio.h>#include <string.h>#include <stdlib.h>#define LINE 3#define RANKvoidCharater_string (intNChar*ptr[]);//String OutputvoidAlphabet_list (intNChar*str[]);//sorted in ASCII alphabetical ordervoidString_length (intNChar*ptr[]);//Sort by string lengthvoidFirst_word_length (intNChar*ptr[]);//Sort by first word lengthintString_in (Char*PTR);//Take the first word character numbervoidQuit ();//Termination procedureintMainvoid){intI,j,num;CharArr[line][rank];Char*string[Line];printf("Please enter Charater string.\n"); for(i=0; i<line;i++) {gets (arr[i]);string[I]=arr[i]; } while(1)     {printf("Please choice number:\n");printf("1) Output string list 2) output string in ASCII order \ n");printf(3) Increment output by length 4) exit \ n by the first word length of the string 5));scanf("%d", &num);Switch(num) { Case 1: Charater_string (line,string); Break; Case 2: Alphabet_list (line,string); Break; Case 3: String_length (line,string); Break; Case 4: First_word_length (line,string); Break; Case 5: Quit (); Break;default: Break; }     }return 0;}voidCharater_string (intNChar*ptr[]) {intI=0; for(i=0; i<n;i++)puts(Ptr[i]);}voidAlphabet_list (intNChar*str[]) {intI,j;Char*temp; for(i=0; i<n-1; i++) { for(j=i+1; j<n;j++) {if(strcmp(Str[i],str[j]) >0) {temp= str[j];              Str[j]= Str[i];            str[i]= temp; }}} charater_string (N,STR);}voidString_length (intNChar*ptr[]) {intI,j;Char*temp; for(i=0; i<n-1; i++) { for(j=i+1; j<n;j++) {if((strlen(Ptr[i])-strlen(Ptr[j])) >0) {Temp=ptr[j];             Ptr[j]=ptr[i];            ptr[i]= temp; }}} charater_string (N,ptr);}voidFirst_word_length (intNChar*ptr[]) {intI,j;Char*temp; for(i=0; i<n-1; i++) { for(j=i+1; j<n;j++) {if((String_in (Ptr[i])-string_in (Ptr[j])) >0) {Temp=ptr[j];             Ptr[j]=ptr[i];            Ptr[i]=temp; }}} charater_string (N,ptr);}voidQuit () {Exit(1);}intString_in (Char*PTR) {intI=0; while(*PTR) {if(*ptr=="')returnI         i++;       *ptr++; }  }

Sorts the array of strings by function call

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.