C language is output after entering three strings and sorting them alphabetically

Updated on technology 2024-02-11
5 answers
  1. Anonymous users2024-02-06

    if(strcmp(*n[i],*n[j]))temp=n[i]; n[i]=n[j]; n[j]=temp;

    Here's the problem.

    The strcmp return value is the size, but you use if(strcmp(*n[i],*n[j])).

    will only check whether it is equal to 0, and if it is not equal to 0, it will be executed later.

    So it should be if(strcmp(*n[i],*n[j])<0)

    strcmp is too long to forget.,If it doesn't work, change "0 try.,I don't know if it's "" or <).

  2. Anonymous users2024-02-05

    The problem is that in your ex() function, the sorting algorithm uses to pass the address, not the specific value, so after jumping out of the ex() function, all local operations are invalid.

    char *temp to char temp;

    temp=n[i]; n[i]=n[j]; n[j]=temp;Change to temp=*n[i]; n[i]=*n[j]; n[j]=temp;It should be fine.

  3. Anonymous users2024-02-04

    Here are the specific steps:1Defines an array of five strings to store the strings that need to be sorted.

    2.Use the string handler strcmp() to compare the size of the two strings. If string 1 is smaller than string 2, the return value is a negative integer; If string 1 is larger than string 2, the return value is a positive integer; If the two strings are equal, the return value is Establish a nested loop, compare the size between each of the two strings, and sort the strings from smallest to largest.

    4.Outputs five sorted strings. Here's an example of an implementation:

    c#include #include int main() printf("The sorted string is:");for (i = 0; i < 5; +i) puts(str[i]);Output five strings after the destruction of the pants lead sorted return 0; Note that the gets() and puts() functions are used when importing and outputting strings, respectively. This is because gets() can input strings that contain spaces, while puts() automatically adds a line break at the end of the output string.

    Also pure picking, the string is larger when comparing using the strcmp() function.

    Be careful to place it in an if statement to meet the requirement of sorting from smallest to largest in the order of English characters. Hope this answer is helpful to you. If you still have any questions or need further help, please feel free to continue to consult the cave.

    You can beat the complete **.

    Whole duck. You sort it out.

  4. Anonymous users2024-02-03

    Just take a look at this one**.

    Hope it helps.

  5. Anonymous users2024-02-02

    The source for outputting a set of strings in lexicographic order is as follows:

    #include

    int main ()

    char name[40] ;Declare a storage space called name, and the number of elements in the array is 40

    printf("what is your name ?");Conversion description character n line break.

    scanf("%s,name");Enter a string, using the conversion modifier %s, which represents the input string.

    printf("hello,%s.",name);Output string.

    return 0;

Related questions
6 answers2024-02-11

xiá ōu tíng

Apgull Pavilion. >>>More

28 answers2024-02-11

Elementary school It's good to just say it directly, otherwise you will regret that you didn't say it later. >>>More

12 answers2024-02-11

<> words that don't have the word "bud" in front of the three-word word. >>>More

11 answers2024-02-11

茝 aahh chai3

1) A kind of herb that is said in ancient books. >>>More

8 answers2024-02-11

After the inscription poem", "Sushan Temple" and "Beiyue Temple".