鱼C论坛

 找回密码
 立即注册
查看: 1351|回复: 2

[已解决]一段输入字符串比较的代码出现了输入的问题

[复制链接]
发表于 2017-4-18 11:17:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
#include<string.h>
void main()
{
        void Str_sort(char (*p)[2]);
        char str[10][2];
        int i;
        char (*p)[2];
        printf("please input ten strings:\n");
        for(i=0;i<10;i++)
                scanf("%s",str[i]);
        p=str;
        Str_sort(p);
        printf("Now the sequence is:\n");
        for(i=0;i<10;i++)
                printf("%s\n",str[i]);
}
void Str_sort(char (*p)[2])
{
        int i,j;
        char temp[2],*q=temp;
        for(i=0;i<9;i++)
                for(j=0;j<9-i;j++)
                        if(strcmp(p[j],p[j+1])>0)
                        {
                                strcpy(q,p[j]);
                                strcpy(p[j],p[j+1]);
                                strcpy(p[j+1],q);
                        }
}
最佳答案
2017-4-18 15:01:54
输入时  要空格  分隔
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-4-18 15:01:54 | 显示全部楼层    本楼为最佳答案   
输入时  要空格  分隔
11.JPG
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-18 15:09:51 | 显示全部楼层
QQ截图20170418150901.png
#include <iostream>
void Str_sort(char *p);

int _tmain(int argc, _TCHAR* argv[])
{
        char str[11];
        char *p=0;
        printf("please input ten strings:\n");
        scanf("%s",str);

        Str_sort(str);
        printf("Now the sequence is:\n%s\n",str);
}

void Str_sort(char *a) 
{ 
        int temp,n=strlen(a);
        for(int i=0;i<n-1;i++) 
                for(int j=i+1;j<n;j++) 
                        if(a[i]>a[j]) 
                        { 
                                temp=a[i]; 
                                a[i]=a[j]; 
                                a[j]=temp; 
                        } 
} 
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-18 01:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表