Divide Error

编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其他字符的个数,在主函数中输入字符串以及输出上述的结果。

 #include<stdio.h>

int Letter=0,Digit=0,Space=0,Other=0;
void main()
{
 void calculate(char array[]);
 char a[40];
 printf("input a string:/n");
 gets(a);
 calculate(a);
 printf("letter:%d/ndigit:%d/nspace:%d/nother:%d/n",Letter,Digit,Space,Other);
 getch();
}
void calculate(char array[])
{
 int i;
 for(i=0;array[i]!='/0';i++)
  if(array[i]>='a'&&array[i]<='z'||array[i]>='A'&&array[i]<='Z') Letter++;
  else if(array[i]>='0'&&array[i]<='9') Digit++;
  else if(array[i]==' ') Space++;
  else Other++;
}
输入My address is #123 Shanghai Road,Beijing,100045.
输出letter:30
        digit:9
        space:5
        other:4
返回,再按alt+F5,发现下边多了
        Divide error
 
把全局变量初始化去掉:
#include<stdio.h>
int Letter,Digit,Space,Other;
void main()
{
 void calculate(char array[]);
 char a[40];
 printf("input a string:/n");
 gets(a);
 calculate(a);
 printf("letter:%d/ndigit:%d/nspace:%d/nother:%d/n",Letter,Digit,Space,Other);
 getch();
}
void calculate(char array[])
{
 int i;
 for(i=0;array[i]!='/0';i++)
  if(array[i]>='a'&&array[i]<='z'||array[i]>='A'&&array[i]<='Z') Letter++;
  else if(array[i]>='0'&&array[i]<='9') Digit++;
  else if(array[i]==' ') Space++;
  else Other++;
输入:My address is #123 Shanghai Road,Beijing,100045.
输出:letter:30
            digit:9
            space:5
            other:4
然后弹出对话框:
C:/TC20/TC.EXE
The NTVDM CPU has encountered an illegal instruction.
CS:00a7 IP:03b3 OP:ff ff ff ff 00 Choose 'Close' to terminate the
application.
 
重新运行保存的程序,在输出结果后返回编辑界面再按Alt+F5,看到下边多出一行:Abnomal program termination.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值