C ÓïÑÔÖеÄÖ¸ÕëºÍÄÚ´æй©
http://www.ibm.com/developerworks/cn/aix/library/au-toughgame/index.html
Ó¢ÎÄÔÎÄ
ÒýÑÔ
¶ÔÓÚÈκÎʹÓà C ÓïÑÔµÄÈË£¬Èç¹ûÎÊËûÃÇ C ÓïÑÔµÄ×î´ó·³ÄÕÊÇʲô£¬ÆäÖÐÐí¶àÈË¿ÉÄÜ»á»Ø´ð˵ÊÇÖ¸ÕëºÍÄÚ´æй©
¡£ÕâЩµÄÈ·ÊÇÏûºÄÁË¿ª·¢ÈËÔ±´ó¶àÊýµ÷ÊÔʱ¼äµÄÊÂÏî¡£Ö¸ÕëºÍÄÚ´æ驶ÔijЩ¿ª·¢ÈËÔ±À´ËµËƺõÁîÈËη¾å£¬µ«ÊÇÒ»µ©ÄúÁ˽âÁËÖ¸Õë¼°Æä¹ØÁªÄÚ´æ²Ù×÷µÄ»ù´¡£¬ËüÃǾÍÊÇÄúÔÚ C ÓïÑÔÖÐÓµÓеÄ×îÇ¿´ó¹¤¾ß¡£
±¾ÎĽ«ÓëÄú·ÖÏí¿ª·¢ÈËÔ±ÔÚ¿ªÊ¼Ê¹ÓÃÖ¸ÕëÀ´±à³ÌÇ°Ó¦¸ÃÖªµÀµÄÃØÃÜ¡£±¾ÎÄÄÚÈÝ°üÀ¨£º
µ¼ÖÂÄÚ´æÆÆ»µµÄÖ¸Õë²Ù×÷ÀàÐÍ
ÔÚʹÓö¯Ì¬ÄÚ´æ·ÖÅäʱ±ØÐ뿼Âǵļì²éµã
µ¼ÖÂÄÚ´æй©µÄ³¡¾°
Èç¹ûÄúÔ¤ÏÈÖªµÀʲôµØ·½¿ÉÄܳö´í£¬ÄÇôÄú¾ÍÄܹ»Ð¡ÐıÜÃâÏÝÚ壬²¢Ïû³ý´ó¶àÊýÓëÖ¸ÕëºÍÄÚ´æÏà¹ØµÄÎÊÌâ¡£
ʲôµØ·½¿ÉÄܳö´í£¿
Óм¸ÖÖÎÊÌⳡ¾°¿ÉÄÜ»á³öÏÖ£¬´Ó¶ø¿ÉÄÜÔÚÍê³ÉÉú³Éºóµ¼ÖÂÎÊÌâ¡£ÔÚ´¦ÀíÖ¸Õëʱ£¬Äú¿ÉÒÔʹÓñ¾ÎÄÖеÄÐÅÏ¢À´±ÜÃâÐí¶àÎÊÌâ¡£
»ØÒ³Ê×
δ³õʼ»¯µÄÄÚ´æ
ÔÚ±¾ÀýÖУ¬p
Òѱ»·ÖÅäÁË 10 ¸ö×Ö½Ú¡£Õâ 10 ¸ö×Ö½Ú¿ÉÄÜ°üº¬À¬»øÊý¾Ý£¬Èçͼ 1
Ëùʾ¡£
char *p = malloc ( 10 );
ͼ 1. À¬»øÊý¾Ý
Èç¹ûÔÚ¶ÔÕâ¸ö p
¸³ÖµÇ°£¬Ä³¸ö´úÂë¶Î³¢ÊÔ·ÃÎÊËü£¬Ôò¿ÉÄÜ»á»ñµÃÀ¬»øÖµ£¬ÄúµÄ³ÌÐò¿ÉÄܾßÓв»¿ÉÔ¤²âµÄÐÐΪ¡£p
¿ÉÄܾßÓÐÄúµÄ³ÌÐò´ÓδÔøÔ¤Áϵ½µÄÖµ¡£
Á¼ºÃµÄʵ¼ùÊÇʼÖÕ½áºÏʹÓà memset
ºÍ malloc
£¬»òÕßʹÓà calloc
¡£
char *p = malloc (10);
memset(p,’\0’,10);
ÏÖÔÚ£¬¼´Ê¹Í¬Ò»¸ö´úÂë¶Î³¢ÊÔÔÚ¶Ô p
¸³ÖµÇ°·ÃÎÊËü£¬¸Ã´úÂë¶ÎÒ²ÄÜÕýÈ·´¦Àí Null
Öµ£¨ÔÚÀíÏëÇé¿öÏÂÓ¦¾ßÓеÄÖµ£©£¬È»ºó½«¾ßÓÐÕýÈ·µÄÐÐΪ¡£
»ØÒ³Ê×
Äڴ渲¸Ç
ÓÉÓÚ p
Òѱ»·ÖÅäÁË 10 ¸ö×Ö½Ú£¬Èç¹ûij¸ö´úÂëƬ¶Î³¢ÊÔÏò p
дÈëÒ»¸ö 11 ×Ö½ÚµÄÖµ£¬Ôò¸Ã²Ù×÷½«ÔÚ²»¸æËßÄúµÄÇé¿öÏÂ×Ô¶¯´ÓÆäËûij¸öλÖÓ³Ôµô”Ò»¸ö×Ö½Ú¡£ÈÃÎÒÃǼÙÉèÖ¸Õë q
±íʾ¸ÃÄÚ´æ¡£
ͼ 2. Ôʼ q ÄÚÈÝ
ͼ 3. ¸²¸ÇºóµÄ q ÄÚÈÝ
½á¹û£¬Ö¸Õë q
½«¾ßÓдÓδԤÁϵ½µÄÄÚÈÝ¡£¼´Ê¹ÄúµÄÄ£¿é±àÂëµÃ×ã¹»ºÃ£¬Ò²¿ÉÄÜÓÉÓÚij¸ö¹²´æÄ£¿éÖ´ÐÐijЩÄÚ´æ²Ù×÷¶ø¾ßÓв»ÕýÈ·µÄÐÐΪ¡£ÏÂÃæµÄʾÀý´úÂëƬ¶ÎÒ²¿ÉÒÔ˵Ã÷ÕâÖÖ³¡¾°¡£
char *name = (char *) malloc(11);
// Assign some value to name
memcpy ( p,name,11); // Problem begins here
ÔÚ±¾ÀýÖУ¬memcpy
²Ù×÷³¢ÊÔ½« 11 ¸ö×Ö½Úдµ½ p
£¬¶øºóÕß½ö±»·ÖÅäÁË 10 ¸ö×Ö½Ú¡£
×÷ΪÁ¼ºÃµÄʵ¼ù£¬Ã¿µ±
Ïà¹ØÎĵµ£º
1¡¢C/C++³ÌÐòÔ±Çë×¢Ò⣬²»ÄÜÔÚcaseÓï¾ä²»Îª¿Õʱ“ÏòÏÂÖ´ÐД¡£
2¡¢ÖµÀàÐͺÍÒýÓÃÀàÐÍÖ®¼äµÄÇø±ð£ºC#µÄ»ù±¾ÀàÐÍ£¨int£¬charµÈ£©¶¼ÊÇÖµÀàÐÍ£¬ÊÇÔÚÕ»Öд´½¨µÄ¡£¶ø¶ÔÏóÊÇÒýÓÃÀàÐÍ£¬´´½¨ÓÚ¶ÑÖУ¬ÐèҪʹÓùؼü×Önew¡£
3¡¢ÔÚC#ÖÐͨ¹ýʵÀý·ÃÎʾ²Ì¬·½·¨»ò³ÉÔ±±äÁ¿ÊDz»ºÏ·¨µÄ£¬»áÉú³É±àÒëÆ÷´íÎó¡£µ«ÊÇÎÒÃÇ¿ÉÒÔͨ¹ýÉùÃ÷ËûÃÇ ......
linuxÏÂÃæ´®¿Ú¹¤¾ßC-kermit C-kermitÊÇÒ»¿î¼¯³ÉÁËÍøÂçͨÐÅ¡¢´®¿ÚͨÐŵŤ¾ß£¬ËüÓÐÈç϶àÖÖ¹¦ÄÜ
1.Ö§³ÖkermitÎļþ´«ÊäÐÒé
2.×Ô¶¨ÒåÁËÒ»Öֽű¾ÓïÑÔ£¬ËüÇ¿´ó¶øÒ×ÓÚʹÓ㬿ÉÓÃÓÚ×Ô¶¯»¯¹¤×÷
3.ÎÞÂÛÊÇÍøÂçͨÐÅ£¬»¹ÊÇ´®¿ÚͨÐÅ£¬²Ù×÷ÊÇÒ»Öµģ¬²¢Ö§³Ö¶àÖÖÓ²¼þ¡¢Èí¼þƽ̨
4.Óа²È«ÈÏÖ¤¡¢¼ÓÃܹ¦ÄÜ
5.ÄÚ½¨FTP¡¢HTTP¿Í»§¶Ë¹ ......
ÖÚËùÖÜÖª£¬strcmpΪ×Ö´®±È½ÏÖ»Ó㬼òµ¥µÄº¯Êý²¢²»¼òµ¥¡£
ÏÂÃæµÄ´úÂë
int main()
{
char* cp1 = {'z', 'h', 'a', 'n', 'g'};
char* cp2 = {'z', 'h', 'a', 'n', 'g'};
std::cout<<strcmp(cp1, cp2)<< ......
1 ÔÚ½â¾ö·½°¸ÖÐÌí¼ÓWindows°²×°ÏîÄ¿
˼·: A ÆäËüÏîÄ¿ÀàÐÍ->°²×°ºÍ²¿Êð
B Ñ¡Ôñ°²×°ÏîÄ¿Ä£°å
2 Íê³É³ÌÐòµÄÌí¼Ó
˼·: A Ñ¡ÖÐÓ¦ÓóÌÐòÎļþ¼Ð->ÓÒ¼üÑ¡ÔñÌí¼ÓÎļþ->
Ñ¡ÖÐÓ¦ÓóÌÐò(ÏîÄ¿Ãû.exe)£¨Íê³É³ÌÐòµÄ´ò°ü£ ......