c语言中编写一个函数 long fun( char s[ ])将一个数字字符串转换成一个整数

如题所述

long fun(char s[])
{
int i;
int nLen;
long lResult;

nLen = strlen(s);
lResult = 0;
for (i=0; i<nLen; i++)
{
if ((s[i]>=0) &&(s[i]<=9))
{
lResult *= 10;
lResult += s[i];
}
else
{
break;
}
}
return lResult;
}
比较简单的实现了下,错误处理没做
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-12
#include <stdlib.h>
long fun( char s[ ])
{
return atoi(s);
}