• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 505  文章 - 1034  trackbacks - 0
            <2006年10月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234


            子曾經(jīng)曰過:編程無他,唯手熟爾!

            常用鏈接

            留言簿(94)

            隨筆分類(649)

            隨筆檔案(505)

            相冊

            BCB

            Crytek

            • crymod
            • Crytek's Offical Modding Portal

            Game Industry

            OGRE

            other

            Programmers

            Qt

            WOW Stuff

            搜索

            •  

            積分與排名

            • 積分 - 914552
            • 排名 - 14

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            atoi使用時要注意了

            這樣子寫有問題,可能導致down掉,因為ch沒有結束符.但是我沒看出怎么當?shù)?br>
            2007-10-09  下面這個程序不會當,但是 number 的值可能不是預期的。

            int _tmain(int argc, _TCHAR* argv[])
            {
                
            char ch[1= {0};
                ch[
            0= '9';

                
            int number = ::atoi(ch);

                std::cout 
            << number << std::endl;

                
            return 0;
            }

            以下是atox.c的源碼:
            /***
            *atox.c - atoi and atol conversion
            *
            *       Copyright (c) Microsoft Corporation. All rights reserved.
            *
            *Purpose:
            *       Converts a character string into an int or long.
            *
            ******************************************************************************
            */

            #include 
            <cruntime.h>
            #include 
            <stdlib.h>
            #include 
            <ctype.h>
            #include 
            <mtdll.h>
            #include 
            <tchar.h>
            #ifdef _MBCS
            #undef _MBCS
            #endif  /* _MBCS */

            #ifndef _UNICODE
            #define _tchartodigit(c)    ((c) >= '0' && (c) <= '9' ? (c) - '0' : -1)
            #else  /* _UNICODE */
            int _wchartodigit(wchar_t);
            #define _tchartodigit(c)    _wchartodigit((wchar_t)(c))
            #endif  /* _UNICODE */

            /***
            *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();

                    
            /* skip whitespace */
                    
            while ( __isspace_mt(ptloci, (int)(_TUCHAR)*nptr) )
            #else  /* defined (_MT) && !defined (_UNICODE) */
                    
            while ( _istspace((int)(_TUCHAR)*nptr) )
            #endif  /* defined (_MT) && !defined (_UNICODE) */
                        
            ++nptr;

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

                    total 
            = 0;

                    
            while ( (c = _tchartodigit(c)) != -1 ) {
                        total 
            = 10 * total + c;     /* accumulate digit */
                        c 
            = (_TUCHAR)*nptr++;    /* get next char */
                    }

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


            /***
            *int atoi(char *nptr) - Convert string to long
            *
            *Purpose:
            *       Converts ASCII string pointed to by nptr to binary.
            *       Overflow is not detected.  Because of this, we can just use
            *       atol().
            *
            *Entry:
            *       nptr = ptr to string to convert
            *
            *Exit:
            *       return int value of the string
            *
            *Exceptions:
            *       None - overflow is not detected.
            *
            ******************************************************************************
            */

            int __cdecl _tstoi(
                    
            const _TCHAR *nptr
                    )
            {
                    
            return (int)_tstol(nptr);
            }

            #ifndef _NO_INT64

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

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

                    
            /* skip whitespace */
                    
            while ( __isspace_mt(ptloci, (int)(_TUCHAR)*nptr) )
            #else  /* defined (_MT) && !defined (_UNICODE) */
                    
            while ( _istspace((int)(_TUCHAR)*nptr) )
            #endif  /* defined (_MT) && !defined (_UNICODE) */
                        
            ++nptr;

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

                    total 
            = 0;

                    
            while ( (c = _tchartodigit(c)) != -1 ) {
                        total 
            = 10 * total + c;     /* accumulate digit */
                        c 
            = (_TUCHAR)*nptr++;    /* get next char */
                    }

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

            #endif  /* _NO_INT64 */
            posted on 2007-09-28 09:19 七星重劍 閱讀(1694) 評論(1)  編輯 收藏 引用 所屬分類: PL--c/c++

            FeedBack:
            # re: atoi使用時要注意了 2007-10-09 10:07 rise
            好像在vs2003可以通過。  回復  更多評論
              
            久久亚洲精品无码观看不卡| 波多野结衣中文字幕久久| 久久99精品九九九久久婷婷| 久久久久国产成人精品亚洲午夜| 久久久久久久综合综合狠狠| 国产色综合久久无码有码| 久久精品视频免费| 无码人妻久久一区二区三区蜜桃| 久久精品欧美日韩精品| 色天使久久综合网天天| 国产午夜精品久久久久免费视| 人人狠狠综合88综合久久| 久久国产亚洲精品无码| 欧美国产成人久久精品| 激情久久久久久久久久| 久久99精品久久久久子伦| 久久久久国产精品人妻| 国产无套内射久久久国产| 久久99久久99精品免视看动漫| 7777精品伊人久久久大香线蕉| 国产精品欧美亚洲韩国日本久久| 欧美黑人又粗又大久久久| 久久夜色精品国产噜噜亚洲a| 久久香蕉一级毛片| 久久精品午夜一区二区福利 | 久久九九精品99国产精品| 久久国产成人午夜AV影院| 久久精品国产亚洲AV嫖农村妇女 | 欧美精品乱码99久久蜜桃| 大香网伊人久久综合网2020| 久久精品国产亚洲精品2020| 亚洲人成网亚洲欧洲无码久久| 亚洲伊人久久成综合人影院| 亚洲精品tv久久久久| 一本一本久久a久久精品综合麻豆| 国产精品久久久久久久久久免费| 91久久精品无码一区二区毛片| 国产91久久精品一区二区| 久久天天躁狠狠躁夜夜躁2O2O| 国产亚洲综合久久系列| 99久久精品国产毛片|