cÄÚ´æ·ÖÅä
ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
£¨1£© ´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄ
Õû¸öÔËÐÐÆڼ䶼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static ±äÁ¿¡£
£¨2£© ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯
ÊýÖ´ÐнáÊøʱÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ´¦ÀíÆ÷µÄÖ¸Á
ÖУ¬Ð§Âʺܸߣ¬µ«ÊÇ·ÖÅäµÄÄÚ´æÈÝÁ¿ÓÐÏÞ¡£
£¨3£© ´Ó¶ÑÉÏ·ÖÅ䣬Òà³Æ¶¯Ì¬ÄÚ´æ·ÖÅä¡£³ÌÐòÔÚÔËÐеÄʱºòÓÃmalloc »ònew ÉêÇëÈÎÒâ¶à
ÉÙµÄÄڴ棬³ÌÐòÔ±×Ô¼º¸ºÔðÔÚºÎʱÓÃfree »òdelete ÊÍ·ÅÄÚ´æ¡£¶¯Ì¬ÄÚ´æµÄÉú´æÆÚ
ÓÉÎÒÃǾö¶¨£¬Ê¹Ó÷dz£Áé»î£¬µ«ÎÊÌâÒ²×î¶à¡£
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str£¬ "hello world");
printf(str);
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º³ÌÐò±ÀÀ£¡£
ÒòΪGetMemory ²¢²»ÄÜ´«µÝ¶¯Ì¬Äڴ棬
Test º¯ÊýÖÐµÄ str Ò»Ö±¶¼ÊÇ NULL¡£
strcpy(str£¬ "hello world");½«Ê¹³ÌÐò±À
À£¡£
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º¿ÉÄÜÊÇÂÒÂë¡£
ÒòΪGetMemory ·µ»ØµÄÊÇÖ¸Ïò“Õ»ÄÚ´æ”
µÄÖ¸Õ룬¸ÃÖ¸ÕëµÄµØÖ·²»ÊÇ NULL£¬µ«ÆäÔ
ÏÖµÄÄÚÈÝÒѾ±»Çå³ý£¬ÐÂÄÚÈݲ»¿ÉÖª¡£
void GetMemory2(char **p£¬ int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str£¬ 100);
strcpy(str£¬ "hello");
printf(str);
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º
£¨1£©Äܹ»Êä³öhello
£¨2£©ÄÚ´æй©
void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str£¬ “hello”);
free(str);
if(str £¡= NULL)
{
strcpy(str£¬ “world”);
printf(str);
}
}
ÇëÎÊÔËÐÐTest º¯Êý»áÓÐʲôÑùµÄ½á¹û£¿
´ð£º´Û¸Ä¶¯Ì¬ÄÚ´æÇøµÄÄÚÈÝ£¬ºó¹ûÄÑÒÔÔ¤
ÁÏ£¬·Ç³£Î£ÏÕ¡£
ÒòΪfree(str);Ö®ºó£¬str ³ÉΪҰָÕ룬
if(str £¡= NULL)Óï¾ä²»Æð×÷Óá£
**********************************************************************************************
void GetMemory2(char **p£¬ int num)
{
*p = (
Ïà¹ØÎĵµ£º
3.ÄÚ¹¦Ìâ
¡¡¡¡ÊÔÌâ1£º·Ö±ð¸ø³öBOOL£¬int£¬float£¬Ö¸Õë±äÁ¿ Óë“ÁãÖµ”±È½ÏµÄ if Óï¾ä£¨¼ÙÉè±äÁ¿ÃûΪvar£©
¡¡¡¡½â´ð£º
¡¡¡¡¡¡BOOLÐͱäÁ¿£ºif(!var)
¡¡¡¡¡¡intÐͱäÁ¿£º if(var==0)
¡¡¡¡¡¡floatÐͱäÁ¿£º
¡¡¡¡¡¡const float EPSINON = 0.00001;
¡¡¡¡¡¡if ((x >= - EPSINON) && (x <= EPSI ......
C
ÓïÑÔËùÓи´ÔÓµÄÖ¸ÕëÉùÃ÷£¬¶¼ÊÇÓɸ÷ÖÖÉùÃ÷ǶÌ×¹¹³ÉµÄ¡£ÈçºÎ½â¶Á¸´ÔÓÖ¸ÕëÉùÃ÷ÄØ£¿ÓÒ×ó·¨ÔòÊÇÒ»¸ö¼ÈÖøÃûÓÖ³£Óõķ½·¨¡£²»¹ý£¬ÓÒ×ó·¨ÔòÆäʵ²¢²»ÊÇC
±ê×¼ÀïÃæµÄÄÚÈÝ£¬ËüÊÇ´ÓC
±ê×¼µÄÉùÃ÷¹æ¶¨ÖйéÄɳöÀ´µÄ·½·¨¡£C
±ê×¼µÄÉùÃ÷¹æÔò£¬ÊÇÓÃÀ´½â¾öÈçºÎ´´½¨ÉùÃ÷µÄ£¬¶øÓÒ×ó·¨ÔòÊÇÓÃÀ´½â¾öÈçºÎ±çʶһ¸öÉùÃ÷µÄ£¬Á½Õß¿ ......
Ê×ÏÈ°²×°±ØÐèµÄ¿ª·¢
°ü
sudo apt-get install gcc g++ libgcc1 libg++ make gdb
°²×°MYSQLµÄCÓïÑÔ¿ª·¢°ü
sudo apt-get install libmysql++-dev libmysql++2c2a libmysqlclient15-dev libmysqlclient15off
°ÑlibÎļþ¿½±´µ½¹«ÓÃ
sudo cp /usr/lib/mysql/* /usr/lib/
½¨Á¢Ò»¸öÐÂÎļþtest.cpp
vim test.cpp
ÊäÈëÄÚÈÝ
......
ÏñPHPºÍperlÒ»Ñù£¬MySQLÒ²ÌṩµÄCÓïÑÔʹÓõÄAPI. C´úÂëµÄAPIÊÇËæMySQLÒ»Æð·¢²¼µÄ¡£ Ëü°üº¬ÔÚmysqlclient¿âÖУ¬ ¿ÉÒÔʹC³ÌÐòÀ´·ÃÎÊÊý¾Ý¿â¡£
MySQLÔ´Âë°üÖеÄÐí¶à¿Í»§¶Ë¶¼ÊÇÓÃCдµÄ¡£ Èç¹ûÄãÕýÔÚÕÒʹÓÃÕâЩC APIµÄÀý×Ó£¬ ¿ÉÒÔ¿´¿´¿Í»§¶ËµÄд·¨¡£Äã¿ÉÒÔÔÚMySQLÔ´Âë°üµÄclientsĿ¼ÕÒµ½ÕâЩÀý×Ó¡£
& ......
2009-11-01 17:31:00
1¡¢Standard C£¬°üÀ¨»ù±¾µÄÓï·¨¶¨Ò壬¿âº¯Êý²Î¿¼
http://www-ccs.ucsd.edu/c/
»òÕß
The C Library Reference Guide
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
2¡¢The UNIX Programming Environment
http://www.iu.hio.no/~mark/unix/unix_toc.html
»ò
The Art of ......