求助:如何在STM32单片机程序中使用atoi()函数?
百度里边有
http://baike.baidu.com/link?url= ... xKMSrQ3eZC8lBe3QZ9q
头文件#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
char a[] = "-100";
char b[] = "123";
int c;
c = atoi(a) + atoi(b);
printf("c=%d\n", c);
return 0;
}
自己添加atoi函数的源码
如何添加?请问你有这方面的例程吗?
isspace(int x)
{
if(x==' '||x=='\t'||x=='\n'||x=='\f'||x=='\b'||x=='\r')
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 */
}
暑假了,想学习FPGA的同学们,可以利用暑假期间好好学习下FPGA,我们现在有款初学者的FPGA开发板利器,现在购买还有配套书籍赠送哦:
入门FPGA开发板:
https://item.taobao.com/item.htm ... &id=35911884243
赠送完全配套书籍:
https://item.taobao.com/item.htm ... amp;id=540865636294
有一定基础的同学,可以看下高端的开发板:
https://item.taobao.com/item.htm ... amp;id=520588767908
如果以上两款依然满足不了您的需求,更可以看下更高端的开发板:
https://item.taobao.com/item.htm ... &id=39939126777
有任何问题,欢迎旺旺 QQ来咨询哦!