| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 351 人关注过本帖
标题:这里拿错啦?
只看楼主 加入收藏
何少仪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:91
专家分:170
注 册:2010-3-6
结帖率:94.44%
收藏
已结贴  问题点数:20 回复次数:3 
这里拿错啦?
#include<stdio.h>
#include<string.h>
#define num 5

#define staic printf("输入1源输出,2ascii输出,3 递增输出,4第一个单词长度输出 ,5退出")
   
int main(void)
{  void fun1(char (*str)[100]) ;
   void fun2(char (*str)[100]) ;
   void fun3(char (*str)[100]);
   void cut(char (*str)[100]);
    char name[num][100],(*cc)[100],(*dd)[100],(*ee)[100],*fun,ch;
    int a,b,c;
    for( a=0,gets(name[a]);a<num;gets(name[++a]));
        
     ee=dd=cc=name;
      staic;
    while((ch=getchar())!=5)
    {switch(ch)
    {
        case '1':
        {
         for(int a=0;a<num;a++)
          puts(name[a]);
          break;
        }
        case '2':
        { fun1(cc);
          cut(cc);
          break;}
         case '3':
         {
          fun2(dd);
          cut(dd);
          break;
         }
         case '4':
         {fun3(ee);
          cut(ee);}
    }
    staic;}
   return 0;
    }
         
     
     
         
     void fun3(char (*str)[100])
     {int a,b,c,d;char *tem;
     c=d=0;
      for(a=0;a<num-1;a++)
        for(b=a+1, c=0,d=0;a<num;b++)
          {for( ;c<20;c++)
           if(str[a][c]==' ') break;
          for(;d<20;d++)
          if(str[b][d]== ' ') break;     
         if(c>d) { tem=str[a];
                   str[a]=str[b];
                   str[b]=tem;}
          }
     
     }
         
    void cut(char (*str)[100]) { int a;for(int a=0;a<num;printf("%s",str[a]),a++);}     
           
    void fun2(char (*str)[100])
    {    int a,b;
      char *tem;
    for(a=0;a<num-1;a++)
     for(b=a+1;b<num;b++)
      if(strlen(str[a])>strlen(str[b]))
       {tem=str[a];
       str[a]=str[b];
       str[b]=tem;}
    }
     
         
      void fun1(char (*str)[100])
      {int a,b;char*fun;
          for( a=0;a<num-1; a++)
           {
            for(b=a+1;b<num;b++)
              if(strcmp(str[a],str[b])>=0)
               {fun=str[a];
               str[a]=str[b];
               str[b]=fun;}
           }
      }
搜索更多相关主题的帖子: include 单词 
2010-04-08 14:22
ldg628
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:3
帖 子:526
专家分:3036
注 册:2009-6-23
收藏
得分:16 
include<stdio.h>
#include<string.h>
#define num 5

#define staic printf("输入:\t1源输出,2ascii输出,3 递增输出,4第一个单词长度输出 ,5退出\n")

void fun1(char (*str)[100]);
void fun2(char (*str)[100]);
void fun3(char (*str)[100]);
void cut(char (*str)[100]);

int main(void)
{
    char name[num][100],(*cc)[100],ch;
    int a;

    cc=name;
    for (a=0; a < num; a++)
        gets(name[a]);
    staic;
    while((ch=getchar()) != '5')
    {
        switch(ch)
        {
            case '1':
            {
                for(a=0;a<num;a++)
                    puts(name[a]);
                break;
            }
            case '2':
            {
                fun1(cc);
                cut(cc);                                                                                          
                break;                                                                                            
            }                                                                                                     
            case '3':                                                                                             
            {                                                                                                     
                fun2(cc);                                                                                         
                cut(cc);                                                                                          
                break;                                                                                            
            }                                                                                                     
            case '4':                                                                                             
            {                                                                                                     
                fun3(cc);                                                                                         
                cut(cc);                                                                                          
            }                                                                                                     
        }                                                                                                         
        staic;                                                                                                   
    }                                                                                                            
   return 0;                                                                                                      
}                        
void fun1(char (*str)[100])                                                                                       
{                                                                                                                 
    int a,b;                                                                                                      
    char fun[100];                                                                                                
    for( a=0;a<num-1; a++)                                                                                       
    {                                                                                                            
        for(b=a+1;b<num;b++)                                                                                      
            if(strcmp(str[a],str[b])>=0)                                                                          
            {                                                                                                     
                memcpy(fun, str[a], 100);                                                                        
                memcpy(str[a], str[b], 100);                                                                     
                memcpy(str[b], fun, 100);                                                                         
            }                                                                                                     
    }                                                                                                            
}                                                                                                                 
void fun2(char (*str)[100])                                                                                       
{                                                                                                                 
    int a,b;                                                                                                      
    char fun[100];                                                                                                
    for(a=0;a<num-1;a++)                                                                                          
        for(b=a+1;b<num;b++)                                                                                      
            if(strlen(str[a])>strlen(str[b]))                                                                     
            {                                                                                                     
                memcpy(fun, str[a], 100);                                                                        
                memcpy(str[a], str[b], 100);                                                                     
                memcpy(str[b], fun, 100);                                                                         
            }                                                                                                     
}                  
void fun3(char (*str)[100])                                                                                       
{                                                                                                                 
    int a,b,c,d;                                                                                                  
    char fun[100];                                                                                                
    for (a=0; a<num-1; a++)                                                                                       
        for (b=a+1; b<num; b++)                                                                                   
        {                                                                                                         
            for (c=0; c<20; c++)                                                                                 
                if (str[a][c] == ' ')
                    break;                                                                     
            for (d=0; d<20; d++)                                                                                 
                if (str[b][d] == ' ')
                    break;                                                                     
            if (c > d)                                                                                            
            {                                                                                                     
                memcpy(fun, str[a], 100);                                                                        
                memcpy(str[a], str[b], 100);                                                                     
                memcpy(str[b], fun, 100);                                                                         
            }                                                                                                     
        }                                                                                                         
}                                                                                                                 
                                                                                                                  
void cut(char (*str)[100])                                                                                       
{                                                                                                                 
    int a;                                                                                                        
    for (a=0; a<num; a++)                                                                                         
        puts(str[a]);                                                                                             
}      
具体算法没有动你的,只改了一些格式,去了一些变量, 纠正了一些错误。。。   
你的代码太乱了。。。汗。。。。要养成好的编码习惯,阅读调试才方便
希望对你有帮助
2010-04-08 16:34
czyzhuo
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:17
帖 子:230
专家分:1459
注 册:2010-3-11
收藏
得分:4 

要养成好的编码习惯,阅读调试才方便
2010-04-08 16:38
何少仪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:91
专家分:170
注 册:2010-3-6
收藏
得分:0 
void fun3(char (*str)[100])
     {int a,b,c,d;char tem[100];
     c=d=0;
      for(a=0;a<num-1;a++)
        for(b=a+1, c=0,d=0;a<num;b++)
          {for( ;c<20;c++)
           if(str[a][c]==' ') break;
          for(;d<20;d++)
          if(str[b][d]== ' ') break;     
         if(c>d) { tem=str[a];
                   str[a]=str[b];
                   str[b]=tem;}
          }
     
     }
         
    void cut(char (*str)[100]) { int a;for(int a=0;a<num;printf("%s",str[a]),a++);}     
           
    void fun2(char (*str)[100])
    {    int a,b;
      char tem[100];
    for(a=0;a<num-1;a++)
     for(b=a+1;b<num;b++)
      if(strlen(str[a])>strlen(str[b]))
       {tem=str[a];
       str[a]=str[b];
       str[b]=tem;}
    }
     
         
      void fun1(char (*str)[100])
      {int a,b;char fun[100];
          for( a=0;a<num-1; a++)
           {
            for(b=a+1;b<num;b++)
              if(strcmp(str[a],str[b])>=0)
               {fun=str[a];
               str[a]=str[b];
               str[b]=fun;}
           }                                    
      }                                 //这样也行。谢谢啦。。 会注意的。。

[b] 你要有勇气去听从你直觉和心灵的指示,所有其他的事情都是次要的。
2010-04-08 19:14
快速回复:这里拿错啦?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020685 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved