您的位置:首页 > 其它

从键盘输入一个字符串放在字符数组…

2014-01-13 16:09 323 查看
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void inOrder(char array[], int n );

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

{

   

    char
temp[100];

   
printf("请输入字符串:\n");

   
gets(temp);

    char
a[strlen(temp)+1];

   
strcpy(a,temp);

   
inOrder(a,strlen(temp));

    int k;

    for(k=0;
k<strlen(temp); k++)

    {

      
printf("%c",a[k]);    

    }

   
system("pause");

    return
0;

}

//选择法排序函数

void inOrder(char array[], int n)

{

    int i,
j;

   
char  temp;

    for(i=0;
i<n-1; i++)

    {

      
for(j=i+1; j<n; j++)

      
{

           
if(array[j]>array[i])

           
{

               
temp = array[i];

               
array[i] = array[j];

               
array[j] = temp;

           
}

      
}  

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐