为什么会有Abnormal Program Termination?
如题,要从一字符串中提取数字,放入一数组,程序如下:
#include<stdio.h>
int isdigit(char c)
{
if(c>='0'&&c<='9')
return(1);
else
return(0);
}
int convert(char c)
{
return(c-'0');
}
main()
{
int a[20];
char *str;
char c;
int i=0,j=0,n,s=0,flag=0;
printf("Input a line containing digit(s):\n");
gets(str);
while((c=*(str+i++))!='\0')
{
if(isdigit(c))
{n=convert(c); s=s*10+n; flag=1;}
else if(flag)
{a[j++]=s; flag=0; s=0;}
}
printf("There are %d numbers\n",j);
for(i=0;i<j;i++)
printf("%d\t",a[i]);
}
运行有时能显示数字,但会出现"Abnormal Program Termination",还有时干脆就关闭了,连TC也一起关闭了.不知是不是指针的问题.望赐教!!