鱼C论坛

 找回密码
 立即注册
查看: 1596|回复: 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
输入时  要空格  分隔
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-4-18 15:01:54 | 显示全部楼层    本楼为最佳答案   
输入时  要空格  分隔
11.JPG
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-4-18 15:09:51 | 显示全部楼层
QQ截图20170418150901.png

  1. #include <iostream>
  2. void Str_sort(char *p);

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

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

  12. void Str_sort(char *a)
  13. {
  14.         int temp,n=strlen(a);
  15.         for(int i=0;i<n-1;i++)
  16.                 for(int j=i+1;j<n;j++)
  17.                         if(a[i]>a[j])
  18.                         {
  19.                                 temp=a[i];
  20.                                 a[i]=a[j];
  21.                                 a[j]=temp;
  22.                         }
  23. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-9 00:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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