| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5676 人关注过本帖
标题:c语言【求高手赐教】如何把这两个c程序整合在一起?
只看楼主 加入收藏
wxl249424820
Rank: 2
等 级:论坛游民
帖 子:17
专家分:14
注 册:2010-2-6
结帖率:50%
收藏
 问题点数:0 回复次数:3 
c语言【求高手赐教】如何把这两个c程序整合在一起?
c.zip (1.48 KB)
高手赐教如何把这两个程序合并成一个程序运行.要添加一个选择菜单,例如:选1.基数排序  选2.回文检测. 0.退出  然后根据选择运行所选的功能.  
            
              printf("\n\t\t|----------------------------------------------|");
              printf("\n\t\t|---------  Please input ( 0 - 2 ) ------------|");
              printf("\n\t\t|----------------------------------------------|");
              printf("\n\t\t|             1. 基数排序                      |");
              printf("\n\t\t|             2. 回文检测                      |");
              printf("\n\t\t|             0. Exit                          |");
              printf("\n\t\t|----------------------------------------------|");

[ 本帖最后由 wxl249424820 于 2010-6-18 11:14 编辑 ]
搜索更多相关主题的帖子: c语言 
2010-06-17 19:44
zghnxzdcx
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:550
专家分:1176
注 册:2010-4-6
收藏
得分:0 
把两个程序放到一个文件里,然后把两个主函数改成其他的名字比如function_1和function_2,之后,在程序的最后,写一个新的主函数:
main()
{
  int i;
  loop:;
  printf("\n\t\t|----------------------------------------------|");
  printf("\n\t\t|---------  Please input ( 0 - 2 ) ------------|");
  printf("\n\t\t|----------------------------------------------|");
  printf("\n\t\t|             1. 基数排序                      |");
  printf("\n\t\t|             2. 回文检测                      |");
  printf("\n\t\t|             0. Exit                          |");
  printf("\n\t\t|----------------------------------------------|");
  
  scanf("%d",&i);
  switch(i)
  {
    case 0:return 0;
    case 1:function_1;goto loop;
    case 2:function_2;goto loop;
    default:printf("Input Error!!!");
  }
}

你永远不可能战胜一个纯傻子,因为他会把你的智商拉到和他同一个水平,然后用他的丰富经验打败你。
2010-06-26 10:30
suntea
Rank: 2
等 级:论坛游民
帖 子:59
专家分:88
注 册:2010-6-24
收藏
得分:0 
楼上正确,
但是应该避免使用goto语句
2010-06-26 21:15
wxl249424820
Rank: 2
等 级:论坛游民
帖 子:17
专家分:14
注 册:2010-2-6
收藏
得分:0 
回复 2楼 zghnxzdcx
程序代码:
#include "stdio.h"
#define MAXSIZE 100
#define TRUE 1
#define FALSE 0
typedef struct
{
    char ch[MAXSIZE];
    int curlen;
}
seqstring;

int symstring(seqstring s)
{
    int i,j;
    i=0;j=s.curlen-1;
    while (i<=j)
      if (s.ch[j]) return(FALSE);
      else {i=i+1;j=j-1;}
    return(TRUE);
}

void function_1()
{
    seqstring s;
    int i=0,f;
    printf("输入字符串:");
    gets(s.ch);
    while (s.ch[i]!='\0') i++;
    s.curlen=i;
    f=symstring(s);
    if (f)
    {
        puts(s.ch);
        printf("是回文");
    }
    else 
    {
        puts(s.ch);
        printf("不是回文");
        }
    }


void main()
{ 
   char choose ='\0';
   while (1)                  /*该循环只有一个出口:选择0才可以退出*/
   {    clrscr();
           printf("\n\t\t[----------------------------------------------]");
           printf("\n\t\t|           欢迎使用数据结构实验系统           |");
          printf("\n\t\t|----------------------------------------------|");
          printf("\n\t\t|-----------  请选择数字 ( 0 - 5 ) ------------|");
          printf("\n\t\t|----------------------------------------------|");
        printf("\n\t\t|             1. Add new card                  |");
        printf("\n\t\t|             2. Logout  card                  |");
        printf("\n\t\t|             3. Modify  card                  |");
        printf("\n\t\t|             4. Read    card                  |");
        printf("\n\t\t|             5. Save   money                  |");
        printf("\n\t\t|             0. 退出实验系统                  |");
        printf("\n\t\t|----------------------------------------------|");
        printf("\n\n\n\n\n");
        scanf("%c",& choose);
        switch (choose)
        {   case '1':function_1;break;
           
            case '0':   
                     printf("\n\t\t 您确定要退出吗? (y/n)?");
                     do
                     {
                          scanf("%c",&choose);
                     }
                     while(choose!='Y' && choose!='y' && choose!='N' && choose!='n');
                     if(choose=='Y' || choose =='y')
                     {   
                          exit(0);
                     }
                     else                
                         printf("\n\t\t操作已取消");
                         getch();
                     
                     break;
            default :   printf("\n\t\t您的输入有误,请您重新输入 !");
            getch();
        }
   }
}



//我的程序是这样写的,但是为何我选择0时才有效...选择1时,却总是显示"您的输入有误,请您重新输入 !"这句话..请问要如何修改呢?

我只是只菜鸟,,来学习的
2010-06-30 13:38
快速回复:c语言【求高手赐教】如何把这两个c程序整合在一起?
数据加载中...
 
   



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

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