µÚÁùÕ ×Ö·ûÐÍÊý¾Ý
6.1 ×Ö·ûÐͳ£Á¿×Ö·û³£Á¿,ÓÃÒ»¶Ôµ¥ÒýºÅÀ¨ÆðÀ´µÄµ¥¸ö×Ö·û¡£
Èç,¡® a¡¯¡£ ÆäÖÐÒýºÅÊǽçÏÞ·û,±íÃ÷ÆäÖÐÒ»¸ö×Ö·û ¡£ ×Ö·ûµÄÖµÊÇÖмäµÄ×Ö·û,²»°üÀ¨½çÏÞ·û ¡£ 1ºÍ ¡® 1¡¯
²»Í¬ ¡£
¡® a?,?A?,¶þÕß²»Ò»Ñù ¡£
6.1.1 ×Ö·û³£Á¿ÔÚ CÓïÑÔÖÐ,´æÔÚ×ÅһЩ תÒå×Ö·û ¡£ ÕâЩתÒå×Ö·ûÊÇÒÔ \¿ªÊ¼µÄ ¡£
תÒå×Ö·û º¬Òå
\n »Ø³µ»»ÐÐ
\t ºáÏòÌøµ¹ÏÂÒ»ÖƱíλÖÃ
\v ÊúÏòÌø¸ñ
\b Í˸ñ
\r »Ø³µ
\f ×ßÖ½»»Ò³
\\ ·´Ð±Ïß·û
\¡¯ µ¥ÒýºÅ
\a ÃùÁå
\ooo AsciiÂëΪ 0oooµÄ×Ö·û
\xhh AsciiÂëΪ 0xhhµÄ×Ö·ûÈç,\101,\x41ÊÇ asciiÂëΪ 65£¨ 0101»ò 0x41£©µÄ×Ö·û£¬¼´¡® A¡¯
6.1.2 תÒå×Ö·û³£Á¿×Ö·û´®³£Á¿£ºÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´® ¡£
Àý,"Good Morning! "
×¢Òâ¡® A? Óë,A¡±ÊDz»Í¬×Ö·û´®´æ·Åʱ,ÔÚ×îºó¼ÓÉÏ,\ 0" ¨C¨C ¿Õ×Ö·û¡£
6.1.3 ×Ö·û´®³£Á¿
1,×Ö·û´®µÄ³¤¶ÈÊÇÖ¸×Ö·û´®ÄÚÈݵÄËùº¬×Ö·ûµÄ¸öÊý¡£
È磺,abcde¡±µÄ³¤¶ÈÊÇ 5¡£ÆäÖУ¬Ë«ÒýºÅÊǽçÏÞ·û£¬²»ÊÇ×Ö·û´®µÄÄÚÈÝ£¬µ«×Ö·û´®´æ´¢¿Õ¼äΪ×Ö·û´®³¤¶È +1¡£
2,µ¥¸ö×Ö·ûµÄ×Ö·û´®²»Äܸ³¸ø×Ö·û±äÁ¿¡£
Àý,char c; c=,a,; ÊÇ´íÎóµÄ¡£
×Ö·û´®³£Á¿Óë×Ö·û³£Á¿µÄÇø±ð£º
¢Ù ×Ö·û³£Á¿Óɵ¥ÒýºÅÀ¨ÆðÀ´,×Ö·û´®³£Á¿ÓÉË«ÒýºÅÀ¨ÆðÀ´ ¡£ Èç,¡® a¡¯ºÍ,a¡±¡£
¢Ú ×Ö·û³£Á¿Ö»ÄÜÊǵ¥¸ö×Ö·û,×Ö·û´®³£Á¿Ôò¿ÉÊÇÁã¸ö»ò¶à¸ö×Ö·û ¡£ Èç,¡® abd¡¯ÊDz»ºÏ·¨µÄ ¡£ µ« ¡® ¡¯ ÊǺϷ¨µÄ ¡£,¡±,,Ò»¶þ,ÊǺϷ¨µÄ ¡£
¢Û ×Ö·û³£Á¿Õ¼Ò»¸ö×Ö½ÚµÄÄÚ´æ¿Õ¼ä,×Ö·û´®³£Á¿Õ¼µÄÄÚ´æ×Ö½ÚÊýµÈÓÚ×Ö·û´®µÄ³¤¶È¼Ó 1¡£
6.1.3 ×Ö·û´®³£Á¿×Ö·û±äÁ¿¿É×÷ÕûÊý²ÎÓëÔËËã¡£
Àý 1,main ( )
{ char c1,c2;
c1=97;
c2=98;
printf ("%c %c",c1,c2)
}
ÔËÐнá¹û a b
6.1.4 ¿É¶Ô×Ö·ûÁ¿½øÐеÄÔËËãÀý 2,main ( )
{ char c1,c2;
c1= ' a ';
c2=' b ';
c1=c1¨C 32; c2=c2¨C 32;
printf ("%c %c",c1,c2)
}
ÔËÐнá¹û A B
6.1.4 ¿É¶Ô×Ö·ûÁ¿½øÐеÄÔËËã
6.2 ×Ö·û±äÁ¿×Ö·û±äÁ¿,ÓÃÀ´´æ·ÅÒ»¸ö×Ö·ûµÄ±äÁ¿ ¡£
¶¨Ò巽ʽΪ£º
char c1,c2;
c1=' A ';
c2= ' B ';
×Ö·û±äÁ¿Ö»Õ¼Ò»¸ö×Ö½Úµ¥Ôª¡£ Ò»¸ö×Ö·û´æÈëÒ»¸ö×Ö·û±äÁ¿¡£Æä¶ÔÓ¦µ¥Ôª´æ·ÅµÄÊÇÆä ASCIIÂë,¼´ ASCIIÂëµÄ¶þ½øÖÆÐÎʽ¡£
Òò´Ë£¬×Ö·û±äÁ¿ÖеÄÊý¾ÝÊÇÒ»ÕûÐÍÊý¾Ý¡£Êä³öʱ¼È¿ÉÊä³ö×Ö·û£¬Òà¿ÉÊä³öÕûÊý£¬ÇÒ×Ö·û±äÁ¿¿É×÷ÕûÊýÔËËã¡£
6.3 ×Ö·ûµÄÊäÈëºÍÊä³öÓà printfº¯ÊýÊä³ö×Ö·ûʱʹÓøñʽ˵Ã÷ %c
Èç,char c=' a';
printf("%c",c);
ÈôÓÐÒ»ÕûÐͱäÁ¿,ÆäÖµÔÚ 0~255Ö®¼ä£¬Ôò¿ÉÒÔ×Ö·ûÐÎʽÊä³ö
Ò»¸ö×Ö·ûÐͱäÁ¿Òà¿ÉÒÔÒ»¸öÕûÐÍÊý¾ÝÊä³ö
6.3.1 µ÷Óà printfºÍ scanfº¯ÊýÊä³öºÍÊäÈë×Ö·ûÀý,main ( )
{ char c='a'£»
int i=97;
printf ("%c,%d\n",c,c);
printf ("%c,%d\n",i,i); }
ÔËÐнá¹ûΪ,a,97
a,97
¿ÉÒÔÖ¸¶¨Êä³ö×Ö·û¿í¶È£¬±ÈÈç printf (¡°%3c¡±,c)£» Êä³ö£º
,€€ a¡±,¼´ c±äÁ¿Êä³öÕ¼ 3ÁУ¬Ç° 2Áв¹¿Õ¸ñ¡£
6.3.1 µ÷Óà printfºÍ scanfº¯ÊýÊä³öºÍÊäÈë×Ö·ûÓà scanfº¯ÊýÊäÈë×Ö·ûʱʹÓøñʽ˵Ã÷ %c
Èç,char c,a; int b;
scanf("%c",&c);
scanf(¡°%d%c¡±,&b,&c);
scanf(¡°%4c%4c¡±,&c,&a);
µÚ¶þÌõÊäÈëÓï¾äµÄÊäÈë¸ñʽ,20w
µÚÈýÌõÊäÈëÓï¾äµÄÊäÈë¸ñʽ,x €€ € y€ € €
6.3.1 µ÷Óà printfºÍ scanfº¯ÊýÊä³öºÍÊäÈë×Ö·ûÐÎʽ,putchar (c );
¹¦ÄÜ,ÏòÖÕ¶Ë (Ò»°ãΪÏÔʾÆ÷ )Êä³öÒ»¸ö×Ö·û,ÆäÖÐ cΪ ×Ö·ûÐÍ»òÕûÐͱäÁ¿,´Ëº¯ÊýµÄ·µ»ØÖµÊÇÆäÊä³öµÄ×Ö·ûµÄÖµ¡£
×¢Òâ,Óøú¯Êýʱ,ÐëÓÃÔ¤±àÒëÃüÁî,
#include "stdio.h "
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÀý,#include "stdio.h"
main( )
{ char a,b,c;
a='B' ; b='O' ; c='Y';
putchar(a); putchar(b); putchar ( C);
}
ÔËÐнá¹û,BOY
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÈô½«×îºóÒ»ÐиÄΪ,
putchar(a); putchar(' \n '); putchar(b); putchar(' \n ');
putchar(c); putchar(' \n ');
ÔËÐнá¹û,B
O
Y
ÀûÓà putchar»¹¿ÉÊä³öÆäËüתÒå×Ö·û
putchar(' \101 ')£» Êä³ö A
putchar(? \ ); Êä³ö¡¯
putchar(? \015?)£» Êä³ö ¨L
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÐÎʽ,getchar( )
¹¦ÄÜ,´Ó±ê×¼ÊäÈë×°Öà (¼üÅÌ )ÉÏÊäÈëÒ»¸ö×Ö·û,´Ëº¯ÊýµÄ·µ»ØÖµÊÇËù»ñµÃµÄ×Ö·ûµÄÖµ¡£
×¢Òâ,Óøú¯Êýʱ,ÐëÓÃÔ¤±àÒëÃüÁî,
#include "stdio.h "
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÀý,#include "stdio.h"
main ( )
{ char c;
c=getchar ( );
putchar (c );
}
getchar() º¯ÊýûÓвÎÊý
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·û
6.1 ×Ö·ûÐͳ£Á¿×Ö·û³£Á¿,ÓÃÒ»¶Ôµ¥ÒýºÅÀ¨ÆðÀ´µÄµ¥¸ö×Ö·û¡£
Èç,¡® a¡¯¡£ ÆäÖÐÒýºÅÊǽçÏÞ·û,±íÃ÷ÆäÖÐÒ»¸ö×Ö·û ¡£ ×Ö·ûµÄÖµÊÇÖмäµÄ×Ö·û,²»°üÀ¨½çÏÞ·û ¡£ 1ºÍ ¡® 1¡¯
²»Í¬ ¡£
¡® a?,?A?,¶þÕß²»Ò»Ñù ¡£
6.1.1 ×Ö·û³£Á¿ÔÚ CÓïÑÔÖÐ,´æÔÚ×ÅһЩ תÒå×Ö·û ¡£ ÕâЩתÒå×Ö·ûÊÇÒÔ \¿ªÊ¼µÄ ¡£
תÒå×Ö·û º¬Òå
\n »Ø³µ»»ÐÐ
\t ºáÏòÌøµ¹ÏÂÒ»ÖƱíλÖÃ
\v ÊúÏòÌø¸ñ
\b Í˸ñ
\r »Ø³µ
\f ×ßÖ½»»Ò³
\\ ·´Ð±Ïß·û
\¡¯ µ¥ÒýºÅ
\a ÃùÁå
\ooo AsciiÂëΪ 0oooµÄ×Ö·û
\xhh AsciiÂëΪ 0xhhµÄ×Ö·ûÈç,\101,\x41ÊÇ asciiÂëΪ 65£¨ 0101»ò 0x41£©µÄ×Ö·û£¬¼´¡® A¡¯
6.1.2 תÒå×Ö·û³£Á¿×Ö·û´®³£Á¿£ºÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´® ¡£
Àý,"Good Morning! "
×¢Òâ¡® A? Óë,A¡±ÊDz»Í¬×Ö·û´®´æ·Åʱ,ÔÚ×îºó¼ÓÉÏ,\ 0" ¨C¨C ¿Õ×Ö·û¡£
6.1.3 ×Ö·û´®³£Á¿
1,×Ö·û´®µÄ³¤¶ÈÊÇÖ¸×Ö·û´®ÄÚÈݵÄËùº¬×Ö·ûµÄ¸öÊý¡£
È磺,abcde¡±µÄ³¤¶ÈÊÇ 5¡£ÆäÖУ¬Ë«ÒýºÅÊǽçÏÞ·û£¬²»ÊÇ×Ö·û´®µÄÄÚÈÝ£¬µ«×Ö·û´®´æ´¢¿Õ¼äΪ×Ö·û´®³¤¶È +1¡£
2,µ¥¸ö×Ö·ûµÄ×Ö·û´®²»Äܸ³¸ø×Ö·û±äÁ¿¡£
Àý,char c; c=,a,; ÊÇ´íÎóµÄ¡£
×Ö·û´®³£Á¿Óë×Ö·û³£Á¿µÄÇø±ð£º
¢Ù ×Ö·û³£Á¿Óɵ¥ÒýºÅÀ¨ÆðÀ´,×Ö·û´®³£Á¿ÓÉË«ÒýºÅÀ¨ÆðÀ´ ¡£ Èç,¡® a¡¯ºÍ,a¡±¡£
¢Ú ×Ö·û³£Á¿Ö»ÄÜÊǵ¥¸ö×Ö·û,×Ö·û´®³£Á¿Ôò¿ÉÊÇÁã¸ö»ò¶à¸ö×Ö·û ¡£ Èç,¡® abd¡¯ÊDz»ºÏ·¨µÄ ¡£ µ« ¡® ¡¯ ÊǺϷ¨µÄ ¡£,¡±,,Ò»¶þ,ÊǺϷ¨µÄ ¡£
¢Û ×Ö·û³£Á¿Õ¼Ò»¸ö×Ö½ÚµÄÄÚ´æ¿Õ¼ä,×Ö·û´®³£Á¿Õ¼µÄÄÚ´æ×Ö½ÚÊýµÈÓÚ×Ö·û´®µÄ³¤¶È¼Ó 1¡£
6.1.3 ×Ö·û´®³£Á¿×Ö·û±äÁ¿¿É×÷ÕûÊý²ÎÓëÔËËã¡£
Àý 1,main ( )
{ char c1,c2;
c1=97;
c2=98;
printf ("%c %c",c1,c2)
}
ÔËÐнá¹û a b
6.1.4 ¿É¶Ô×Ö·ûÁ¿½øÐеÄÔËËãÀý 2,main ( )
{ char c1,c2;
c1= ' a ';
c2=' b ';
c1=c1¨C 32; c2=c2¨C 32;
printf ("%c %c",c1,c2)
}
ÔËÐнá¹û A B
6.1.4 ¿É¶Ô×Ö·ûÁ¿½øÐеÄÔËËã
6.2 ×Ö·û±äÁ¿×Ö·û±äÁ¿,ÓÃÀ´´æ·ÅÒ»¸ö×Ö·ûµÄ±äÁ¿ ¡£
¶¨Ò巽ʽΪ£º
char c1,c2;
c1=' A ';
c2= ' B ';
×Ö·û±äÁ¿Ö»Õ¼Ò»¸ö×Ö½Úµ¥Ôª¡£ Ò»¸ö×Ö·û´æÈëÒ»¸ö×Ö·û±äÁ¿¡£Æä¶ÔÓ¦µ¥Ôª´æ·ÅµÄÊÇÆä ASCIIÂë,¼´ ASCIIÂëµÄ¶þ½øÖÆÐÎʽ¡£
Òò´Ë£¬×Ö·û±äÁ¿ÖеÄÊý¾ÝÊÇÒ»ÕûÐÍÊý¾Ý¡£Êä³öʱ¼È¿ÉÊä³ö×Ö·û£¬Òà¿ÉÊä³öÕûÊý£¬ÇÒ×Ö·û±äÁ¿¿É×÷ÕûÊýÔËËã¡£
6.3 ×Ö·ûµÄÊäÈëºÍÊä³öÓà printfº¯ÊýÊä³ö×Ö·ûʱʹÓøñʽ˵Ã÷ %c
Èç,char c=' a';
printf("%c",c);
ÈôÓÐÒ»ÕûÐͱäÁ¿,ÆäÖµÔÚ 0~255Ö®¼ä£¬Ôò¿ÉÒÔ×Ö·ûÐÎʽÊä³ö
Ò»¸ö×Ö·ûÐͱäÁ¿Òà¿ÉÒÔÒ»¸öÕûÐÍÊý¾ÝÊä³ö
6.3.1 µ÷Óà printfºÍ scanfº¯ÊýÊä³öºÍÊäÈë×Ö·ûÀý,main ( )
{ char c='a'£»
int i=97;
printf ("%c,%d\n",c,c);
printf ("%c,%d\n",i,i); }
ÔËÐнá¹ûΪ,a,97
a,97
¿ÉÒÔÖ¸¶¨Êä³ö×Ö·û¿í¶È£¬±ÈÈç printf (¡°%3c¡±,c)£» Êä³ö£º
,€€ a¡±,¼´ c±äÁ¿Êä³öÕ¼ 3ÁУ¬Ç° 2Áв¹¿Õ¸ñ¡£
6.3.1 µ÷Óà printfºÍ scanfº¯ÊýÊä³öºÍÊäÈë×Ö·ûÓà scanfº¯ÊýÊäÈë×Ö·ûʱʹÓøñʽ˵Ã÷ %c
Èç,char c,a; int b;
scanf("%c",&c);
scanf(¡°%d%c¡±,&b,&c);
scanf(¡°%4c%4c¡±,&c,&a);
µÚ¶þÌõÊäÈëÓï¾äµÄÊäÈë¸ñʽ,20w
µÚÈýÌõÊäÈëÓï¾äµÄÊäÈë¸ñʽ,x €€ € y€ € €
6.3.1 µ÷Óà printfºÍ scanfº¯ÊýÊä³öºÍÊäÈë×Ö·ûÐÎʽ,putchar (c );
¹¦ÄÜ,ÏòÖÕ¶Ë (Ò»°ãΪÏÔʾÆ÷ )Êä³öÒ»¸ö×Ö·û,ÆäÖÐ cΪ ×Ö·ûÐÍ»òÕûÐͱäÁ¿,´Ëº¯ÊýµÄ·µ»ØÖµÊÇÆäÊä³öµÄ×Ö·ûµÄÖµ¡£
×¢Òâ,Óøú¯Êýʱ,ÐëÓÃÔ¤±àÒëÃüÁî,
#include "stdio.h "
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÀý,#include "stdio.h"
main( )
{ char a,b,c;
a='B' ; b='O' ; c='Y';
putchar(a); putchar(b); putchar ( C);
}
ÔËÐнá¹û,BOY
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÈô½«×îºóÒ»ÐиÄΪ,
putchar(a); putchar(' \n '); putchar(b); putchar(' \n ');
putchar(c); putchar(' \n ');
ÔËÐнá¹û,B
O
Y
ÀûÓà putchar»¹¿ÉÊä³öÆäËüתÒå×Ö·û
putchar(' \101 ')£» Êä³ö A
putchar(? \ ); Êä³ö¡¯
putchar(? \015?)£» Êä³ö ¨L
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÐÎʽ,getchar( )
¹¦ÄÜ,´Ó±ê×¼ÊäÈë×°Öà (¼üÅÌ )ÉÏÊäÈëÒ»¸ö×Ö·û,´Ëº¯ÊýµÄ·µ»ØÖµÊÇËù»ñµÃµÄ×Ö·ûµÄÖµ¡£
×¢Òâ,Óøú¯Êýʱ,ÐëÓÃÔ¤±àÒëÃüÁî,
#include "stdio.h "
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·ûÀý,#include "stdio.h"
main ( )
{ char c;
c=getchar ( );
putchar (c );
}
getchar() º¯ÊýûÓвÎÊý
6.3.2 µ÷Óà putcharºÍ getcharº¯ÊýÊä³öºÍÊäÈë×Ö·û