| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 477 人关注过本帖
标题:求助 程序强制结束
只看楼主 加入收藏
kingsunbin
Rank: 1
等 级:新手上路
帖 子:2
专家分:3
注 册:2014-4-21
结帖率:0
收藏
已结贴  问题点数:5 回复次数:2 
求助 程序强制结束
程序代码如下:
#include"stdio.h"
#include"string.h"
#include"windows.h"
#include"ctype.h"
#include"stdlib.h"

int main()
{
    int count = 0;
    char number[5];
    char enumber[9][6] = {"One","Two","Three","Four","Five","Six" ,"Seven","Eight","Nine"};
    char bnumber[11][11] = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty"};
    char cnumber[10][9] = {"Twenty","Thirty","Fouty","Tifty","Sixty","Seventy","Eighty","Ninty"};
    int s;
    char anwser;
   
   
   
   
   while(1)
   {
    printf("请输入一个1000的正整数:\n");
    scanf("%5s",number);
   
    count = strlen(number);
   
   
   
   
    if(number[0]=='0')                     //检查机制
      {
        printf("error");
        return 1;
        }
    for(int i=0;count>i;i++)               //检查机制
    {
            if(isdigit(number[i])==0)
               {
                   printf("error!");
                   system("pause");
                   return 1;
                }
    }                                 
   
   
   
    if(count==1)                        //是否为一位
    {
      s = atoi(number);
      printf("%s\n\n",enumber[s-1]);
    }      
    if(count==2)                       //是否为两位
    {
      s = atoi(number);
      if(s>=10&&s<=20)
        printf("%s\n\n",s%10==0?(s==20?bnumber[10]:bnumber[0]):bnumber[s%10]);
      else
        printf("%s %s\n\n",cnumber[s/10-2],s%10==0?"":enumber[(s%10)-1]);  
      }
      
     printf("输入N/n结束程序:");
     scanf("%1c",anwser);
     if(toupper(anwser)=='N')
       break;
}   

system("pause");
return 0;
                  
}
编译运行这个程序后,会自己强制结束,说出现问题,停止工作。问题截图在附件中
[附件]问题截图[/附件]
搜索更多相关主题的帖子: Seventeen include number count 
2014-04-25 16:16
kwxx
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:309
专家分:913
注 册:2009-5-11
收藏
得分:5 
说说你程序的用途吧。
2014-04-25 16:32
kwxx
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:309
专家分:913
注 册:2009-5-11
收藏
得分:0 
主要是倒数第7行少了地址符:  scanf("%c",&anwser);            //<-------------少了地址符


//转数字为相应英文单词
#include"stdio.h"
#include"string.h"
#include"windows.h"
#include"ctype.h"
#include"stdlib.h"

int main()
{
    int count = 0;
    char number[10];
    char enumber[9][6] = {"One","Two","Three","Four","Five","Six" ,"Seven","Eight","Nine"};
    char bnumber[11][11] = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen","Twenty"};
    char cnumber[10][9] = {"Twenty","Thirty","Fouty","Tifty","Sixty","Seventy","Eighty","Ninty"};
    int s;
    char anwser;   
   
   while(1)
   {
    printf("请输入一个100以内的正整数:\n");
    scanf("%s",number);                //<---------%5s一定是5个字符,与后面的讨论矛盾  
    count = strlen(number);   
   
    if(number[0]=='0')                     //检查机制--第一位不能是0
      {
        printf("error");
        return 1;
        }
    for(int i=0;count>i;i++)               //检查机制--其他位不能非数字
    {
            if(isdigit(number[i])==0)
               {
                   printf("error!");
                   system("pause");
                   return 1;
                }
    }                                 
   
   
   
    if(count==1)                        //是否为一位
    {
      s = atoi(number);
      printf("%s\n\n",enumber[s-1]);
    }else if(count==2)                       //是否为两位
    {
      s = atoi(number);
      if(s>=10&&s<=20)
        printf("%s\n\n",bnumber[s-10]);
      else
        printf("%s %s\n\n",cnumber[s/10-2],s%10==0?"":enumber[(s%10)-1]);  
      }
      
     printf("输入N/n结束程序:"); getchar();
     scanf("%c",&anwser);            //<-------------少了地址符
     if(toupper(anwser)=='N')
       break;
}   

system("pause");
return 0;
                  
}

2014-04-25 17:08
快速回复:求助 程序强制结束
数据加载中...
 
   



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

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