第2个回答 2007-12-03
#include <stdio.h>
#include <ctype.h>
/*
判断字符串是否为数字字符串
return 1:是数字字符串
0:不是数字字符串
*/
int IsDigit(char *str)
{
bool flag=true;
int nod=0;//记录小数点位数
for (char* p=str;*p; ++p)
{
if (isdigit(*p))
{
continue;
}
else if (*p=='.')
{
if (++nod>1)//小数点位数大于1时不是数字字符串
{
return 0;
}
}
else
{
return 0;
}
}
return 1;
}
int main()
{
char *str="1234.67";
if (IsDigit(str))
{
printf("%s是数字字符串\n",str);
}
else
{
printf("%s不是数字字符串\n",str);
}
return 0;
}