求助:如何在STM32单片机程序中使用atoi()函数?

2019-07-15 12:02发布

如何在STM32单片机程序中使用atoi()函数?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
海滨
2019-07-16 05:01
Gmy1860 发表于 2017-2-10 21:04
如何添加?请问你有这方面的例程吗?

isspace(int x)
{
if(x==' '||x==' '||x==' '||x=='f'||x==''||x==' ')
  return 1;
else  
  return 0;
}
isdigit(int x)
{
if(x<='9'&&x>='0')         
  return 1;x`
else
  return 0;

}
int atoi(const char *nptr)
{
        int c;              /* current char */
        int total;         /* current total */
        int sign;           /* if '-', then negative, otherwise positive */

        /* skip whitespace */
        while ( isspace((int)(unsigned char)*nptr) )
            ++nptr;

        c = (int)(unsigned char)*nptr++;
        sign = c;           /* save sign indication */
        if (c == '-' || c == '+')
            c = (int)(unsigned char)*nptr++;    /* skip sign */

        total = 0;

        while (isdigit(c)) {
            total = 10 * total + (c - '0');     /* accumulate digit */
            c = (int)(unsigned char)*nptr++;    /* get next char */
        }

        if (sign == '-')
            return -total;
        else
            return total;   /* return result, negated if necessary */
}

一周热门 更多>