• <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
            <2008年11月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456


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

            常用鏈接

            留言簿(94)

            隨筆分類(649)

            隨筆檔案(505)

            相冊

            BCB

            Crytek

            • crymod
            • Crytek's Offical Modding Portal

            Game Industry

            OGRE

            other

            Programmers

            Qt

            WOW Stuff

            搜索

            •  

            積分與排名

            • 積分 - 914465
            • 排名 - 14

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            atoi使用時(shí)要注意了

            這樣子寫有問題,可能導(dǎo)致down掉,因?yàn)閏h沒有結(jié)束符.但是我沒看出怎么當(dāng)?shù)?br>
            2007-10-09  下面這個(gè)程序不會(huì)當(dāng),但是 number 的值可能不是預(yù)期的。

            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使用時(shí)要注意了 2007-10-09 10:07 rise
            好像在vs2003可以通過。  回復(fù)  更多評論
              
            久久综合狠狠综合久久97色| 久久中文字幕人妻丝袜| 国产精品99久久久久久人| 精品久久久久久久久中文字幕| 国产99久久精品一区二区| 久久黄视频| 97久久国产露脸精品国产| 久久夜色精品国产噜噜麻豆| 91久久香蕉国产熟女线看| 中文精品久久久久人妻| 成人综合伊人五月婷久久| 欧美精品一区二区久久| 国产精品9999久久久久| 国内精品久久久久影院亚洲| 国产亚洲精久久久久久无码AV| av色综合久久天堂av色综合在| 婷婷综合久久狠狠色99h| 久久久久久国产精品美女| 99久久精品免费看国产一区二区三区| 狠狠色狠狠色综合久久| 久久久久国产精品麻豆AR影院| 亚洲精品美女久久久久99| 久久人人超碰精品CAOPOREN | 久久福利青草精品资源站| 日本加勒比久久精品| 青青草原综合久久| 久久久无码精品亚洲日韩按摩| 久久精品二区| 狠狠狠色丁香婷婷综合久久五月| 影音先锋女人AV鲁色资源网久久 | 久久精品二区| 日韩人妻无码一区二区三区久久99 | 国产免费久久精品丫丫| 国产精品国色综合久久| 久久久久无码精品国产| 国产精品久久久久久五月尺| 久久精品国产色蜜蜜麻豆| 天天综合久久久网| 久久国产精品无码网站| 国产精品丝袜久久久久久不卡 | 97久久精品人妻人人搡人人玩|