Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C/C++ ѧϰ±Ê¼Ç[03].È¥µôC·ç¸ñµÄ×¢ÊÍ

ÍøÉÏËÑË÷ÁËÒ»´ó¶ÑÈ¥µô/*ºÍ*/Ö®¼ä×¢Ê͵ĴúÂë,¾ÍÏñ<The C Programming Language>Á·Ï°1-23ÀïÓÐÈË˵µÄÒ»Ñù
´ó²¿·Ö¶¼»á±»ÒÔϵijÌÐòbroken,Õâ¸ö¹¦ÄÜ¿´ÆðÀ´¼òµ¥,ʵ¼ÊÉϺÜÓÐÄѶÈ.ÍøÉÏʵÏֵĴúÂë,³ýÁËÎÒÕÒµ½µÄÒ»¸öÓÃÎļþÖ¸ÕëʵÏÖµÄûÓÐÎÊÌâÍâ,ÆäÓàµÄ¶¼´æÔÚ¸÷ÖÖbug,²»ÐŵĻ°¾ÍÓÃÒÔϵijÌÐò²âÊÔÒ»ÏÂ:-),µ±È»Õâ¸ö³ÌÐòÒ²²»¹»ÍêÉÆ.
»¹ÊÇÓÐÏÞ״̬×Ô¶¯»úʵÏÖÆðÀ´¸üÑϽ÷Ò²ÈÝÒ×Àí½âµÃ¶à:
/* krx123tp.c - a test program to serve as input to krx123*.c
*
* This is a shameless copy of Ben Pfaff's solution, to which I have
* added a few extra statements to further test the candidate programs
* for this exercise. As Ben says, this program already contains lots
* of examples of comments and not-quite-comments. I've just made it
* a little tougher.
*
*/
/* K&R2 1-23: Write a program to remove all comments from a C program.
Don't forget to handle quoted strings and character constants
properly. C comments do not nest.
This solution does not deal with other special cases, such as
trigraphs, line continuation with \, or <> quoting on #include,
since these aren't mentioned up 'til then in K&R2. Perhaps this is
cheating.
Note that this program contains both comments and quoted strings of
text that looks like comments, so running it on itself is a
reasonable test. It also contains examples of a comment that ends
in a star and a comment preceded by a slash. Note that the latter
will break C99 compilers and C89 compilers with // comment
extensions.
Interface: The C source file is read from stdin and the
comment-less output is written to stdout. **/
#include <stdio.h>
int
main(void)
{
/* State machine's current state. */
enum {
PROGRAM,
SLASH,
COMMENT,
STAR,
QUOTE,
LITERAL
} state;
/* If state == QUOTE, then ' or ". Otherwise, undefined. */
int quote;
state = PROGRAM;
for (;;) {
int c = getchar();
if (c == EOF)


Ïà¹ØÎĵµ£º

C\C++ byte»òÕßcharÊý×éתintÖµ

¼ÙÉèÓÐchar a[2];
ÈçÒª°Ñaת»»ÎªintÖµ¡£Ó¦ÊÇÈçÏÂд·¨int b=*(int *)a;
¼´£¬ÏÈ°ÑÖ¸Õëa ת»»ÎªÒ»¸öintÖ¸Õ룬ȻºóÔÙ´Ë»ù´¡ÉÏÈ¡Öµ¡£
µ«ÊÇÁíÒ»ÖÖд·¨ int b=(int)(*a);ÊDz»¶ÔµÄ£¬*a È¡aµÄÄÚ´æµ¥ÔªÄÚÈÝ£¬ÒòΪÏÖÔÚaÊÇcharÖ¸Õ룬ËùÒÔÖ»»áÈ¡a[1]ÖÐÄÚÈÝ£¬×î´óΪ255. ÕâÀïҪ˵Ã÷µÄÊÇ£¬ÔÚ°Ñchar»òbyteÊý×éת»»ÎªÆäËûÀàÐ͵Äֵʱ£¬ÒªÏÈ ......

c¿âº¯ÊýÏê½â——assert

c¿âº¯ÊýÏê½â——assert
º¯ÊýÃû: assert
¹¦  ÄÜ: ²âÊÔÒ»¸öÌõ¼þ²¢¿ÉÄÜʹ³ÌÐòÖÕÖ¹
Óà ·¨: void assert(int test);
³ÌÐòÀý:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
struct ITEM {
   int key;
   int value;
};
/* add item to ......

¡¾×ª¡¿CµÄÁíÒ»ÖØÒªÊý¾Ý½á¹¹bit fields

½ñÌì¿´K&RµÄÊéµÄʱºò˳±ãÎÂÏ°ÁËCµÄÁíÒ»ÖØÒªÊý¾Ý½á¹¹bit-fields£¬ÎÒÏëbit-fieldsÔÚ±àдµ×²ãÇý¶¯
Çý¶¯³ÌÐòµÄʱºòÓ¦¸Ã±È½ÏºÃÓã¬Ëü¿ÉÒÔÈÆ¿ª"&"ºÍ"|"½øÐÐλ²Ù×÷£¬¶øÇÒ¸ü¼Ó½ÚÔ¼ÄÚ´æ¿Õ¼ä¡£·Ï»°²»¶à˵
ÁË£¬»¹ÊÇÏÈÀ´¿´¿´ËüµÄÕæÃæÄ¿°É£º
bit-fieldÀ´Ô´:
bit-fieldÊÇΪÁ˽ÚÔ¼´æ´¢¿Õ¼ä¶ø´´ÔìµÄÒ»ÖÖÊý¾ ......

¼òÊöCºÍC++³ÌÐòԱѧϰÀú³Ì

¹þ¹þ£¡ÓÐÐÒÔÚijÍøÕ¾·¢ÏÖÕâƪÎÄÕ£¬¶Á°Õ£¬¾õµÃÂùÓеÀÀí£¬·¢À´´ó¼ÒÒ»Æð¹²ÃãÖ®    
×ÜÊDZ»Í¬Ñ§ÃÇÎʵ½£¬ÈçºÎѧϰCºÍC++²Å²»Ã£È»£¬²Å²»ÊÇÂÒѧ£¬ÏëÁËһϣ¬ÕâÀï¸ø³öÒ»¸ö×ܵĻظ´¡£ 
' J$ |0 ?! p% w" t5 D6 D: c9 |0 B
¡¡¡¡Ò»¼ÒÖ®ÑÔ£¬»¶Ó­ÅÄש¹þ¡£ 
¡¡¡¡1¡¢¿ÉÒÔ¿¼ÂÇÏÈѧϰC. 
/ U$ X+ X/ P; Y ......

CÖ¸ÕëÒÜÏë

Ö¸Õë,ÖÚËùÖÜÖª,ʱΪһÄÚ´æµØÖ·.Å׿ªOS¼¶±ð»ò¸üµÍµÄÓ²¼þ¼¶±ð²»Ëµ,½ö¶ÔÓ¦ÓÃÄÚµÄʹÓýøÐÐССµÄÒܲâÌÖÂÛ.
Ê×ÏÈ,ÔÚÓ¦ÓÃÄÚ,ÓÃmallocÉêÇëµ½µÄÒ»¿éµØÖ·Ó¦¸ÃÊÇÁ¬ÐøµÄ(²Â²â,Âß¼­ÉÏÁ¬Ðø,ʵ¼ÊÉÏÎïÀíÈçºÎ·Ö²¼²»Óè¹Ø×¢).
Æä´Î,Êý¾Ý´æÔÚÔÚÄÚ´æÖж¼ÊÇÒÔ2½øÖÆÐÎʽ´æ·Å.²»´æÔÚÊý¾ÝÀàÐÍ,Òò´Ë,¶ÔÄÚ´æÊý¾ÝµÄ²Ù×÷,Ö»Òª×ñÑ­½ø³öÀàÐÍÒ»Ö¼´¿É.
´ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ