The input string is output according to the asc value-General Linux technology-Linux programming and kernel information. The following is a detailed description. Programming Language c
# Include
# Include
Char * sort (char * s)
{
Int I, j, lenth;
Char temp;
Lenth = strlen (s );
For (j = 0; j For (I = 0; I If (* (s + I)> = * (s + I + 1 ))
{
Temp = * (s + I );
* (S + I) = * (s + I + 1 );
* (S + I + 1) = temp;
}
Return s;
}
Int main ()
{
Char str1 [500] = {0 };
Printf ("please input some characters :");
Gets (str1 );
Sort (str1 );
Printf ("ASC number small to big: % s", str1 );
Printf ("\ n ");
}
Knowledge Point: function call bubble sorting
Note: The characters can be compared with each other.
Appendix: Although Tan Haoqiang's c also has the bubble method, the program in the book is flawed for (I = 0; I Compiling with gcc in ubuntu may cause errors.
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.