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

正文內容

c程序設計第6章-利用數(shù)組處理批量數(shù)據(jù)-資料下載頁

2025-07-25 18:07本頁面
  

【正文】 strcpy(str1,″China″); ?( 3)復制時連同字符串后面的 ′\ 0′一起復制到字符數(shù)組 1中。 ?( 4)可以用 strncpy函數(shù)將字符串 2中前面若干個字符復制到字符數(shù)組 1中去。例如 :strncpy(str1, str2, 2)。作用是將 str2中前面2個字符復制到 str1中去,然后再加一個 ′\ 0′ 。復制的字符個數(shù) n不應多于 str1中原有的字符。 關于 strcpy函數(shù)的幾點說明 ?( 5)不能用賦值語句將一個字符串常量或字符數(shù)組直接給一個字符數(shù)組。如: str1=″China″。 不合法 str1=str2。 不合法 ?用 strcpy函數(shù)只能將一個字符串復制到另一個字符數(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′。 5. strcmp函數(shù) 字符串比較函數(shù) ?其一般形式為 strcmp(字符串 1,字符串 2) ?作用是比較字符串 1和字符串 2 strcmp(str1,str2)。 strcmp(”China”,”Korea”)。 strcmp(str1,”Beijing”)。 善于使用 字符串處理函數(shù) 5. strcmp函數(shù) 字符串比較函數(shù) ?字符串比較的規(guī)則是:將兩個字符串自左至右逐個字符相比,直到出現(xiàn)不同的字符或遇到 ?\0?為止 。 ?如全部字符相同,認為兩個字符串相等 。 ?若出現(xiàn)不相同的字符,則以第一對不相同的字符的比較結果為準 。 ?比較的結果由函數(shù)值帶回: ?如果字符串 1=字符串 2,則函數(shù)值為 0 ?如果字符串 1字符串 2,則函數(shù)值為一個正整數(shù) ?如果字符串 1字符串 2,則函數(shù)值為一個負整數(shù) 善于使用 字符串處理函數(shù) 5. strcmp函數(shù) 字符串比較函數(shù) ”A””B” ”a””A” ”puter””pare” ”these””that” ”1A””$20” ”CHINA””CANADA” ”DOG””cat” ”Tsinghua””TSINGHUA” 善于使用 字符串處理函數(shù) 5. strcmp函數(shù) 字符串比較函數(shù) if(str1str2) printf(”yes”)。 錯誤 if(strcmp(str1,str2)0) printf(”yes”)。 正確 善于使用 字符串處理函數(shù) 6. strlen函數(shù) 測字符串長度的函數(shù) ?其一般形式為 : strlen (字符數(shù)組 ) ?它是測試字符串長度的函數(shù) , 函數(shù)的值為字符串中的實際長度 。 ? 例如: char str[10]=”China”。 printf(”%d”,strlen(str))。 輸出結果是 5 ?也可以直接測試字符串常量的長度 strlen(”China”)。 善于使用 字符串處理函數(shù) 7. strlwr函數(shù) 轉換為小寫的函數(shù) ?其一般形式為 strlwr (字符串 ) ?函數(shù)的作用是將字符串中大寫字母換成小寫字母 8. strupr函數(shù) 轉換為大寫的函數(shù) ?其一般形式為 strupr (字符串 ) ?函數(shù)的作用是將字符串中小寫字母換成大寫字母 善于使用 字符串處理函數(shù) 例 輸入一行字符,統(tǒng)計其中有多少個單詞,單詞之間用空格分隔開。 include int main() { char string[81]。 int i,num=0,word=0。 char c。 gets(string)。 for (i=0。(c=string[i])!=39。\039。i++) if(c==39。 39。) word=0。 else if(word==0) { word=1。 num++。 } printf(There are %d words in this line.\n,num)。 return 0。 } 運行情況如下: I am a boy.↙ There are 4 words in the line. 例 有 3個字符串 ,要求找出其中最大者。 include include int main ( ) { char str[3][20]。 char string[20]。 int i。 for (i=0。i3。i++) gets (str[i])。 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)。 return 0。 } 運行結果如下 : CHINA↙ HOLLAND↙ AMERICA↙ the largest string is∶ HOLLAND
點擊復制文檔內容
公司管理相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1