freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

第7章_數(shù)組-資料下載頁

2025-09-25 19:15本頁面
  

【正文】 of ″}。 char str2[] ={″China″}。 print(″%s″ , strcat(str1, str2))。 輸出: People′s Republic of China C程序設(shè)計(第三版) 59 4. strcpy函數(shù) 其一般形式為 : strcpy(字符數(shù)組 1,字符串 2) strcpy是 “ 字符串復(fù)制函數(shù) ” 。 作用是將字符串 2復(fù)制到字符數(shù)組 1中去 。 例如: char str1[ 10] , str2[ ] ={″ China″ }。 strcpy(str1, str2)。 C程序設(shè)計(第三版) 60 關(guān)于 strcpy函數(shù)的幾點說明 ( 1) 字符數(shù)組 1必須定義得足夠大,以便容納被復(fù)制的字符串。字符數(shù)組 1的長度不應(yīng)小于字符串 2的長度。 ( 2) “ 字符數(shù)組 1”必須寫成數(shù)組名形式(如 str1), “ 字符串 2”可以是字符數(shù)組名 ,也可以是一個字符串常量 。 如 strcpy(str1,″ China″ ); C程序設(shè)計(第三版) 61 ( 3) 復(fù)制時連同字符串后面的 ′ \ 0′ 一起復(fù)制到字符數(shù)組 1中 。 ( 4) 可以用 strcpy函數(shù)將字符串 2中前面若干個字符復(fù)制到字符數(shù)組 1中去 。 例如 :strcpy(str1, str2, 2)。 作用是將 str2中前面 2個字符復(fù)制到 str1中去 , 然后再加一個 ‘ \ 0’。 C程序設(shè)計(第三版) 62 ( 5) 不能用賦值語句將一個字符串常量或字符數(shù)組直接給一個字符數(shù)組 。 如: str1=″ China″ 。 不合法 str1=str2。 不合法 ?用 strcpy函數(shù)只能將一個字符串復(fù)制到另一個字符數(shù)組中去 。 ?用賦值語句只能將一個字符賦給一個字符型變量或字符數(shù)組元素 。 下面是合法的使用 : char a[ 5] , c1, c2。 c1=′ A′ 。 c2=′ B′ 。 a[ 0] =′ C′ 。 a[ 1] =′ h′ 。 a[ 2] =′ i′ 。 a[ 3] =′ n′ 。 a[ 4] =′ a′ 。 C程序設(shè)計(第三版) 63 5. strcmp函數(shù) 其一般形式為 : strcmp(字符串 1,字符串 2) strcmp的作用是比較字符串 1和字符串 2。 例如: strcmp(str1, str2)。 strcmp(″ China″ , ″ Korea″ )。 strcmp(str1, ″ Beijing″ )。 C程序設(shè)計(第三版) 64 比較的結(jié)果由函數(shù)值帶回 (1) 如果字符串 1=字符串 2,函數(shù)值為 0。 (2) 如果字符串 1字符串 2,函數(shù)值為一正整數(shù)。 (3) 如果字符串 1字符串 2,函數(shù)值為一負整數(shù)。 注意: 對兩個字符串比較,不能用以下形式: if(str1str2) printf(″yes″)。 而只能用 if(strcmp(str1, str2)0) printf(″yes″)。 C程序設(shè)計(第三版) 65 6. strlen函數(shù) 其一般形式為 : strlen (字符數(shù)組 ) strlen是測試字符串長度的函數(shù) 。 函數(shù)的值為字符串中的實際長度 (不包括 ′ \ 0′ 在內(nèi) )。 例如: char str[ 10] ={″ China″ }。 printf(″% d″ , strlen(str))。 輸出結(jié)果不是 10, 也不是 6, 而是 5。 也可以直接測試字符串常量的長度 , 如 strlen(″ China″ ); C程序設(shè)計(第三版) 66 7. strlwr函數(shù) 其一般形式為 : strlwr (字符串 ) strlwr函數(shù)的作用是將字符串中大寫字母換成小寫字母 。 8. strupr函數(shù) 其一般形式為 : strupr (字符串 ) strupr函數(shù)的作用是將字符串中小寫字母換成大寫字母 。 C程序設(shè)計(第三版) 67 例 7 .8 輸入一行字符,統(tǒng)計其中有多少個單詞,單 詞之間用空格分隔開。 C程序設(shè)計(第三版) 68 程序如下: include void main() { char string[ 81] 。 int i, num=0, word=0。 char c。 gets(string)。 for (i=0。(c=string[ i] )!=′\ 0′。i++) C程序設(shè)計(第三版) 69 if(c==′ ′) word=0。 else if(word==0) { word=1。 num++。 } printf(″There are %d words in the line.\ n″, num)。 } 運行情況如下: I am a boy.↙ There are 4 words in the line. C程序設(shè)計(第三版) 70 例 有 3個字符串 ,要求找出其中最大者 程序如下 : include include void main ( ) { char string[ 20] 。 char str[ 3][ 20] 。 int i。 for (i=0。i3。i++) gets (str[ i] )。 C程序設(shè)計(第三版) 71 if (strcmp(str[ 0] ,str[ 1] )0) strcpy(string,str[ 0] ) else strcpy(string,str[ 1] )。 if (strcmp(str[ 2] ,string)0) strcpy(string,str[ 2] )。 printf(″\ nthe largest string is∶ \ n%s\ n″,string)。 } C程序設(shè)計(第三版) 72 運行結(jié)果如下 : CHINA↙ HOLLAND↙ AMERICA↙ the largest string is∶ HOLLAN
點擊復(fù)制文檔內(nèi)容
外語相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1