比较10个字符串大小

来源:互联网 发布:公司海关出口数据查询 编辑:程序博客网 时间:2024/05/08 13:10

#include"stdio.h"

void sort(char *p){
    int i,j;
    char s[10],*smax,*smin;
    for(i=0;i<10;i++){
        smax=p+10*i;
        for(j=0;j<10;j++){
            smin=p+10*j;
            if(strcmp(smin,smax)>0){
                strcpy(s,smin);
                strcpy(smin,smax);
                strcpy(smax,s);
            }
        }
    }
}

void main(){
    int i;
    char *p,str[10][10];
    printf("enter 10 strs:/n");

    for(i=0;i<10;i++){
   
        scanf("%s",str[i]);
    }
    p=&str[0][0];
   
    sort(p);

    printf("after sort:/n");
    for(i=0;i<10;i++){
        printf("%s/n",str[i]);
    }
}

原创粉丝点击