设计函数 int atoi(char *s)。(高手帮帮小弟)

来源:百度知道 编辑:UC知道 时间:2024/06/14 17:54:39
请高手指点,是联想的一道笔试题
还有:2.int i=(j=4,k=8,l=16,m=32); printf(“%d”, i); 输出是多少?
3.论述含参数的宏与函数的优缺点。
急啊~~谢谢啦
如果第2,3题能够详细点就好了.....谢谢
譬如第2题是如何运算的.
还有,3楼和4楼的答案有出入.究竟是谁的正确啊,我是初学者,请达人们指教指教啊~~~

1。微软的VC++中的实现
/***
*long atol(char *nptr) - Convert string to long
*
*Purpose:
* Converts ASCII string pointed to by nptr to binary.
* Overflow is not detected.
*
*Entry:
* nptr = ptr to string to convert
*
*Exit:
* return long int value of the string
*
*Exceptions:
* None - overflow is not detected.
*
*******************************************************************************/

long __cdecl _tstol(
const _TCHAR *nptr
)
{
int c; /* current char */
long total; /* current total */
int sign; /* if '-', then negative, otherwise positive */
#if defined (_MT) && !defined (_UNICODE)
pthreadlocinfo ptloci = _getptd()->ptlocinfo;

if ( ptloci != __ptlocinfo )
ptloci = __updatetlocinfo();