11.07.2015 Views

Characters and Strings

Characters and Strings

Characters and Strings

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

35Function reverse (fig08_13.c)24 void reverse( const char * const sPtr )25 {26 /* if end of the string */27 if ( sPtr[ 0 ] == '\0' ) {28 return;29 } /* end if */30 else { /* if not end of the string */31 reverse( &sPtr[ 1 ] );32© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.非 library function33 putchar( sPtr[ 0 ] ); /* use putchar to display character */34 } /* end else */3536 } /* end function reverse */Running example of function reverse36reverse(“abc”);sPtr[ 0 ] != '\0', callreverse(&sPtr[1])sPtr[ 0 ] != '\0', callreverse(&sPtr[1])sPtr[ 0 ] != '\0', callreverse(&sPtr[1])reverse(“bc”);reverse(“c”);reverse(“\0”);sPtr[ 0 ] == '\0',returnputchar(sPtr[0]);returnputchar(sPtr[0]);returnputchar(sPtr[0]);return印 ‘a’印 ‘b’印 ‘c’© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.1


練 習 五39• 使 用 getchar() 函 數 抓 取 使 用 者 逐 次 輸 入 的 字元 , 如 果 輸 入 字 元 是 英 文 字 母 或 white space則 留 下 , 如 果 是 其 它 字 元 則 略 掉 。 將 留 下 的 英文 字 母 轉 換 成 頭 字 大 寫 的 型 式 輸 出例 :ab48.7c輸 出 Abc利 用 前 頁 的 while 迴 圈-58f70.e +g11zX#輸 出 Fe Gzx空 格© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.練 習 六• 用 getchar() 函 數 使 讓 使 用 者 輸 入 一 個 數 字 字串 , 輸 出 此 數 字 ( 可 為 實 數 ) 乘 以 3.0 的 結 果• 要 求 1: 除 0 至 9、 正 負 號 及 小 數 點 外 其 它 的 輸 入一 律 忽 略• 要 求 2: 正 負 號 只 能 出 現 在 數 字 前 面• 要 求 3: 小 數 點 最 多 出 現 一 次48.7 ok-58.70 ok+10 ok2fk10 忽 略 fk2.0.9 忽 略 第 二 個 `.’-2.0-/9 忽 略 第 二 個 `-’ 及 `/’40© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.3


41sprintf 與 sscanf•int sprintf( char *s, const char*format, ... );–Equivalent to printf, except the output isstored in the array s instead of printing iton the screen.•int sscanf( char *s, const char*format, ... );–Equivalent to scanf, except the input isread from the array s instead of reading itfrom the keyboard.© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.sprintf (fig08_15.c)42char s[ 80 ]; /* create char array */int x; /* define x */double y; /* define y */將 輸 出 放printf( "Enter an integer <strong>and</strong> a double:\n" );入 字 串 s 中scanf( "%d%lf", &x, &y );sprintf( s, "integer:%6d\ndouble:%8.2f", x, y );printf( "%s\n%s\n","The formatted output stored in array s is:", s );Enter an integer <strong>and</strong> a double:298 87.375The formatted output stored in array s is:integer: 298字 串 sdouble: 87.38© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.4


sscanf (fig08_16.c)43char s[] = "31298 87.375"; /* initialize array s */int x; /* define x */double y; /* define y */sscanf( s, "%d%lf", &x, &y );printf( "%s\n%s%6d\n%s%8.3f\n","The values stored in character array s are:","integer:", x, "double:", y );The values stored in character array s are:integer: 31298double: 87.375xy從 字 串 s 中取 得 輸 入© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.8.6 String Manipulation Functions of theString H<strong>and</strong>ling Library•String h<strong>and</strong>ling library has functions to–Manipulate string data–Search strings–Tokenize strings–Determine string lengthFunction prototype Function descriptionchar *strcpy( char Copies string s2 into array s1. The value of s1 is returned.*s1, const char*s2 )char *strncpy( char Copies at most n characters of string s2 into array s1. The value of s1*s1, const char is returned.*s2, size_t n )char *strcat( char*s1, const char*s2 )char *strncat( char*s1, const char*s2, size_t n )Appends string s2 to array s1. The first character of s2 overwrites theterminating null character of s1. The value of s1 is returned.Appends at most n characters of string s2 to array s1. The first characterof s2 overwrites the terminating null character of s1. The value of s1 isreturned.44© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.5


strcpy <strong>and</strong> strncpy (fig08_18.c): 字 串 複 製45char x[] = "Happy Birthday to You";char y[ 25 ]; /* create char array y */char z[ 15 ]; /* create char array z */printf( " The string in array y is: %s\n", strcpy( y, x ));strncpy( z, x, 14 ); 只 copy 14 個 字 元z[ 14 ] = '\0'; /* append '\0' to z's contents */printf( "The string in array z is: %s\n", z );The string in array y is: Happy Birthday to YouThe string in array z is: Happy Birthday請 注 意 strcpy 會 copy 字 串 最 後 的 ‘\0’, 但 strncpy 不 見 得 ( 何 時 不 會 ?)© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.46strcat <strong>and</strong> strncat (fig08_19.c): 字 串 連 接char s1[ 20 ] = "Happy ";char s2[] = "New Year "; /* initialize char array s2 */char s3[ 40 ] = ""; /* initialize char array s3 */printf( "strcat( s1, s2 ) = %s\n", strcat( s1, s2 ) );printf( "strncat( s3, s1, 6 ) = %s\n", strncat( s3, s1, 6 ) );printf( "strcat( s3, s1 ) = %s\n", strcat( s3, s1 ) );strcat( s1, s2 ) = Happy New Yearstrncat( s3, s1, 6 ) = Happystrcat( s3, s1 ) = Happy Happy New Year只 連 接 s1 的 前 6 個 字 元 ,後 面 會 自 動 加 個 ‘\0’© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.6


8.7 Comparison Functions of the StringH<strong>and</strong>ling Library•Comparing strings–Computer compares numeric ASCII codes ofcharacters in string–Appendix D has a list of character codes47int strcmp( const char *s1, const char *s2 );–Compares string s1 to s2–Returns a negative number if s1 < s2, zero if s1 ==s2 or a positive number if s1 > s2int strncmp( const char *s1, const char *s2,size_t n );–Compares up to n characters of string s1 to s2–Returns values as above© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.48strcmp (fig08_21.c): 字 串 比 較const char *s1 = "Happy New Year";const char *s2 = "Happy New Year";const char *s3 = "Happy Holidays";printf("%s%2d\n%s%2d\n%s%2d\n\n","strcmp(s1, s2) = ", strcmp( s1, s2 ),"strcmp(s1, s3) = ", strcmp( s1, s3 ),"strcmp(s3, s1) = ", strcmp( s3, s1 ) );strcmp(s1, s2) = 0strcmp(s1, s3) = 1strcmp(s3, s1) = -10 表 相 同1 表 前 面 的 字 串 較 大-1 表 前 面 的 字 串 較 小© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.7


strncmp (fig08_21.c): 限 定 長 度 的 字 串 比 較49const char *s1 = "Happy New Year";const char *s2 = "Happy New Year";const char *s3 = "Happy Holidays";printf("%s%2d\n%s%2d\n%s%2d\n","strncmp(s1, s3, 6) = ", strncmp( s1, s3, 6 ),"strncmp(s1, s3, 7) = ", strncmp( s1, s3, 7 ),"strncmp(s3, s1, 7) = ", strncmp( s3, s1, 7 ) );strncmp(s1, s3, 6) = 0strncmp(s1, s3, 7) = 1strncmp(s3, s1, 7) = -10 表 相 同1 表 前 面 的 字 串 較 大-1 表 前 面 的 字 串 較 小只 比 較 前 面6 個 字 元© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.練 習 七 : strcmp 和 strncmp50• 用 gets() 函 數 讓 使 用 者 輸 入 一 列 文 字• 若 使 用 者 輸 入 “hi” 或 “hello” 則 回 應 相 同 文 字• 若 使 用 者 輸 入 “Do you…” 則 回 應 “Yes, I do.”• 若 使 用 者 輸 入 “Are you…” 則 回 應 “Maybe.”• 若 使 用 者 輸 入 其 它 訊 息 則 回 應 “I know.”© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.8


8.8 Search Functions of the StringH<strong>and</strong>ling LibraryFunction prototype Function description51char *strchr( const char *s,int c );size_t strcspn( const char*s1, const char *s2 );size_t strspn( const char*s1, const char *s2 );char *strpbrk( const char*s1, const char *s2 );char *strrchr( const char *s,int c );char *strstr( const char *s1,const char *s2 );char *strtok( char *s1, constchar *s2 );Locates the first occurrence of character c in string s. If c is found, apointer to c in s is returned. Otherwise, a NULL pointer is returned.Determines <strong>and</strong> returns the length of the initial segment of string s1consisting of characters not contained in string s2.Determines <strong>and</strong> returns the length of the initial segment of string s1consisting only of characters contained in string s2.Locates the first occurrence in string s1 of any character in string s2.If a character from string s2 is found, a pointer to the character instring s1 is returned. Otherwise, a NULL pointer is returned.Locates the last occurrence of c in string s. If c is found, a pointer to cin string s is returned. Otherwise, a NULL pointer is returned.Locates the first occurrence in string s1 of string s2. If the string isfound, a pointer to the string in s1 is returned. Otherwise, a NULLpointer is returned.A sequence of calls to strtok breaks string s1 into “tokens”—logicalpieces such as words in a line of text—separated by characterscontained in string s2. The first call contains s1 as the first argument,<strong>and</strong> subsequent calls to continue tokenizing the same string containNULL as the first argument. A pointer to the current token is returnedby each call. If there are no more tokens when the function is called,© Copyright 1992–2004 by Deitel & Associates, NULL Inc. is<strong>and</strong> returned. Pearson Education Inc. All Rights Reserved.52strchr (fig08_23.c): 在 字 串 中 找 特 定 字 元const char *string = "This is a test";char character1 = 'a';char character2 = 'z';找 到 時 ,strchr 傳 回 指標 , 指 向 找 到 的 字 元 。找 不 到 時 傳 回 NULLif ( strchr( string, character1 ) != NULL ) {printf( "\'%c\' was found in \"%s\".\n", character1, string );}else { /* if character1 was not found */printf( "\'%c\' was not found in \"%s\".\n", character1, string );}'a' was found in "This is a test".© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.9


53strcspn (fig08_24.c)const char *string1 = "The value is 3.14159";const char *string2 = "1234567890";printf( "%s%s\n%s%s\n\n%s\n%s%u","string1 = ", string1, "string2 = ", string2,"The length of the initial segment of string1","containing no characters from string2 = ",strcspn( string1, string2 ) );string1 = The value is 3.14159string2 = 1234567890The length of the initial segment of string1containing no characters from string2 = 13從 string1 最 前 面 開 始算 起 , 直 到 遇 到 任 何string2 中 字 元 的 長 度( 該 字 元 不 算 在 內 )© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.54strpbrk (fig08_25.c)const char *string1 = "This is a test"; /* initialize char pointer */const char *string2 = "beware"; /* initialize char pointer */傳 回 字 元 指 標 , 指 向string1 中 最 先 出 現 與string2 中 任 何 字 元 相符 的 字 元 。 或 NULLprintf( "%s\"%s\"\n'%c'%s\n\"%s\"\n","Of the characters in ", string2,*strpbrk( string1, string2 )," is the first character to appear in ", string1 );Of the characters in "beware"'a' is the first character to appear in"This is a test"© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.10


strrchr (fig08_26.c)const char *string1 = "A zoo has many animals ""including zebras";int c = 'z';55printf( "%s\n%s'%c'%s\"%s\"\n","The remainder of string1 beginning with the","last occurrence of character ", c," is: ", strrchr( string1, c ) );The remainder of string1 beginning with thelast occurrence of character 'z' is: "zebras"傳 回 字 元 指 標 , 指 向string1 中 最 後 出 現 c 字 元 處© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.strspn (fig08_27.c)const char *string1 = "The value is 3.14159";const char *string2 = "aehi lsTuv";56printf( "%s%s\n%s%s\n\n%s\n%s%u\n","string1 = ", string1, "string2 = ", string2,"The length of the initial segment of string1","containing only characters from string2 = ",strspn( string1, string2 ) );string1 = The value is 3.14159string2 = aehi lsTuvThe length of the initial segment of string1containing only characters from string2 = 13© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.計 算 string1 中 屬 於string2 字 元 的 字 元 數 目11


strstr (fig08_28.c): 在 字 串 中 找 特 定 字 串57const char *string1 = "abcdefabcdef";const char *string2 = "def";printf( "%s%s\n%s%s\n\n%s\n%s%s\n","string1 = ", string1, "string2 = ", string2,"The remainder of string1 beginning with the","first occurrence of string2 is: ",strstr( string1, string2 ) );string1 = abcdefabcdefstring2 = defThe remainder of string1 beginning with thefirst occurrence of string2 is: defabcdef傳 回 字 元 指 標 , 指向 string1 中 第 一 個出 現 string2 的 地 方© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.58練 習 八 : strchr 與 strstr• 用 gets() 函 數 讓 使 用 者 輸 入 一 列 英 文 文 字• 利 用 strchr 函 數 計 算 並 輸 出 這 列 文 字 中 出 現 了多 少 個 ‘a’•( 此 項 可 略 過 ) 利 用 strpbrk 函 數 計 算 並 輸 出 這 列文 字 中 出 現 了 多 少 個 母 音 字 母 (a, e, I, o, u)• 利 用 strstr 函 數 計 算 並 輸 出 這 列 文 字 中 出 現 了 多少 個 ‘the’© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.12


59strtok (fig08_29.c): 從 字 串 中 取 出 tokenchar string[] = "This is a sentence with 7 tokens";char *tokenPtr;printf( "%s\n%s\n\n%s\n","The string to be tokenized is:", string,"The tokens are:" );tokenPtr = strtok( string, " " );while ( tokenPtr != NULL ) {printf( "%s\n", tokenPtr );}傳 回 字 元 指 標 , 指向 string 中 的 第 一 個token ( 以 空 格 分 隔 )可 改 成 任 何 你 想 要的 token 分 隔 字 元tokenPtr = strtok( NULL, " " ); /* get next token */傳 回 指 向 下 一 個token 的 字 元 指 標© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.60Output of strtokThe string to be tokenized is:This is a sentence with 7 tokensThe tokens are:Thisisasentencewith7tokens© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.13


61練 習 九 : strtok()• 用 gets() 函 數 讓 使 用 者 輸 入 一 列 型 式 為 a + b,a –b, a * b, 或 a / b 的 運 算 式 , 輸 出 此 運 算 式求 值 的 結 果•a 和 b 可 為 實 數 ( 有 小 數 點 )• 進 階 挑 戰 :a 可 以 有 正 負 符 號• 運 算 子 (+,-,*,/) 與 運 算 元 (a,b) 之 間 可 以 有 若 干 空格© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.8.9 Memory Functions of the Stringh<strong>and</strong>lingLibrary•Memory Functions–In –Manipulate, compare, <strong>and</strong> search blocks ofmemory–Can manipulate any block of data62•Pointer parameters are void *–Any pointer can be assigned to void *, <strong>and</strong> vice versa–void * cannot be dereferenced•Each function receives a size argumentspecifying the number of bytes (characters) toprocess© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.14


8.9 Memory Functions of the Stringh<strong>and</strong>lingLibrary63Function prototypevoid *memcpy( void*s1, const void *s2,size_t n );void *memmove( void*s1, const void *s2,size_t n );int memcmp( constvoid *s1, const void*s2, size_t n );void *memchr( constvoid *s, int c,size_t n );void *memset( void*s, int c, size_t n);Function descriptionCopies n characters from the object pointed to by s2 into the objectpointed to by s1. A pointer to the resulting object is returned.Copies n characters from the object pointed to by s2 into the objectpointed to by s1. The copy is performed as if the characters were firstcopied from the object pointed to by s2 into a temporary array <strong>and</strong>then from the temporary array into the object pointed to by s1. Apointer to the resulting object is returned.Compares the first n characters of the objects pointed to by s1 <strong>and</strong> s2.The function returns 0, less than 0 or greater than 0 if s1 is equal to,less than or greater than s2.Locates the first occurrence of c (converted to unsigned char) in thefirst n characters of the object pointed to by s. If c is found, a pointerto c in the object is returned. Otherwise, NULL is returned.Copies c (converted to unsigned char) into the first n characters ofthe object pointed to by s. A pointer to the result is returned.© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.64memcpy (fig08_31.c): 記 憶 體 內 容 複 製char s1[ 17 ]; /* create char array s1 */char s2[] = "Copy this string"; /* initialize char array s2 */memcpy( s1, s2, 17 );printf( "%s\n%s\"%s\"\n","After s2 is copied into s1 with memcpy,","s1 contains ", s1 );After s2 is copied into s1 with memcpy,s1 contains "Copy this string"將 s2 copy 至 s1,copy 17 bytes© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.15


65strcpy 與 memcpy 的 比 較•strcpy 與 memcpy 有 什 麼 不 同 ?–strcpy 複 製 字 串 , 沒 有 指 定 複 製 內 容 的 長度 , 而 是 以 ‘\0’ 作 為 複 製 結 束 的 標 記–memcpy 複 製 記 憶 體 內 容 , 不 以 ‘\0’ 作 為 複製 結 束 的 標 記 , 故 需 要 指 定 複 製 內 容 的 長 度• 那 strncpy 與 memcpy 又 有 什 麼 不 同 ?–strncpy 指 定 複 製 字 串 的 最 大 允 許 長 度 , 字 串實 際 長 度 可 能 小 於 此 值–memcpy 指 定 複 製 內 容 的 實 際 長 度 , 複 製 內容 的 長 度 一 定 等 於 此 值© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.66memmove (fig08_32.c): 記 憶 體 內 容 搬 移char x[] = "Home Sweet Home"; /* initialize char array x */printf( " The string in array x before memmove is:%s\n", x );printf( "%s%s\n", "The string in array x after memmove is: ",memmove( x, &x[ 5 ], 10 ) );從 x[5] 開 始 copy10 個 字 元The string in array x before memmove is: Home Sweet HomeThe string in array x after memmove is: Sweet Home Home© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.16


memcmp (fig08_33.c)67char s1[] = "ABCDEFG"; /* initialize char array s1 */char s2[] = "ABCDXYZ"; /* initialize char array s2 */比 較 前 4 個 byteprintf( "%s%2d\n%s%2d\n%s%2d\n","memcmp( s1, s2, 4 ) = ", memcmp( s1, s2, 4 ),"memcmp( s1, s2, 7 ) = ", memcmp( s1, s2, 7 ),"memcmp( s2, s1, 7 ) = ", memcmp( s2, s1, 7 ) );memcmp( s1, s2, 4 ) = 0memcmp( s1, s2, 7 ) = -1memcmp( s2, s1, 7 ) = 10 表 相 同-1 表 前 面 的 byte 較 小1 表 前 面 的 byte 較 大© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.memchr (fig08_34.c)68const char *s = "This is a string"; /* initialize char pointer */printf( "%s\'%c\'%s\"%s\"\n","The remainder of s after character ", 'r'," is found is ", memchr( s, 'r', 16 ) );在 s 的 前 16 個 byte 中 找 ’r’傳 回 第 一 個 找 到 位 置The remainder of s after character 'r' is found is "ring“© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.17


memset (fig08_35.c)69char string1[ 15 ] = "BBBBBBBBBBBBBB";printf( "string1 = %s\n", string1 );printf( "string1 after memset = %s\n", memset( string1, 'b', 7 ));string1 = BBBBBBBBBBBBBBstring1 after memset = bbbbbbbBBBBBBB將 string1 的 前 7個 byte 設 為 ‘b’© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.8.10 Other Functions of the String H<strong>and</strong>lingLibrary70•char *strerror( int errornum );–Creates a system-dependent error messagebased on errornum–Returns a pointer to the string•size_t strlen( const char *s );–Returns the number of characters (before NULL) instring s© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.18


71strerror (fig08_37.c)#include …printf( "%s\n", strerror( 2 ) );印 出 2 號 系統 錯 誤 訊 息No such file or directory© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.72strlen (fig08_38.c)const char *string1 = "abcdefghijklmnopqrstuvwxyz";const char *string2 = "four";const char *string3 = "Boston";printf("%s\"%s\"%s%lu\n%s\"%s\"%s%lu\n%s\"%s\"%s%lu\n","The length of ", string1, " is ",( unsigned long ) strlen( string1 ),"The length of ", string2, " is ",( unsigned long ) strlen( string2 ),"The length of ", string3, " is ",( unsigned long ) strlen( string3 ) );2646印 出 string1 長度 ( 不 含 ‘\0’)© Copyright 1992–2004 by Deitel & Associates, Inc. <strong>and</strong> Pearson Education Inc. All Rights Reserved.19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!