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

正文內(nèi)容

c語言課件ppt:第六章數(shù)組-資料下載頁

2024-10-09 14:53本頁面
  

【正文】 tr2[]={“This is a c program”}。 static char str3[]=“This is a c program”。 三、字符數(shù)組的輸入輸出 逐個字符輸入或輸出 :用格式符“ %c”: 例如, scanf(“%c”,amp。str1[i])。 整個字符串輸入輸出:用格式符“ %s”: 例如, scanf(“%s”, str1)。 C [ 0 ] C [ 1 ] C [ 2 ] C [ 3 ] C [ 4 ] C [ 5 ] C [ 6 ] C [ 7 ] C [ 8 ] C [ 9 ] c p r o g r a m39 39 167。 字符數(shù)組 四、 字符數(shù)組的引用 對字符數(shù)組可以逐個元素引用,即逐個字符處理。 例如 main() { int i,j。 char a[5]={39。B39。,39。A39。,39。S39。,39。I39。,39。C39。}; for(j=0。j=4。j++) printf(%c,a[j])。 printf(\n)。 } 40 40 167。 字符數(shù)組 五、字符串 在C語言中沒有專門的字符串變量, 通常用一個字符數(shù)組來存放一個字符串。在介紹字符串常量時,已說明字符串總是以 39。\039。作為串的結(jié)束符。因此當(dāng)把一個字符串存入一個數(shù)組時, 也把結(jié)束符39。\039。存入數(shù)組,并以此作為該字符串是否結(jié)束的標(biāo)志。 有了 39。\039。標(biāo)志后,就不必再用字符數(shù)組的長度來判斷字符串的長度了。 C語言允許用字符串的方式對數(shù)組作初始化賦值。例如: static char c[]={C program}。 或去掉 {}寫為: static char c[]=C program。 main() { char str[15]。 printf(input string:\n)。 scanf(%s,str)。 printf(%s\n,str)。 } 41 41 167。 字符數(shù)組 六、字符串處理函數(shù) puts 格式: puts (字符數(shù)組名 ) 功能:把字符數(shù)組中的字符串輸出到顯示器。 即在屏幕上顯 示該字符串。 例如, main() { static char c[]=BASIC\ndBASE。 puts(c)。 } 從程序中可以看出 puts函數(shù)中可以使用轉(zhuǎn)義字符, 因此輸出結(jié)果成為兩行。 puts函數(shù)完全可以由 printf函數(shù)取代。 當(dāng)需要按一定格式輸出時,通常使用 printf函數(shù)。 結(jié)果: BASIC dBASE 42 42 六、字符串處理函數(shù) gets 格式: gets (字符數(shù)組名 ) 功能:從標(biāo)準(zhǔn)輸入設(shè)備鍵盤上輸入一個字符串。本函數(shù)得到 一個函數(shù)值,即為該字符數(shù)組的首地址 。 例如, include main() { char st[15]。 printf(input string:\n)。 gets(st)。 puts(st)。 } 可以看出當(dāng)輸入的字符串中含有空格時,輸出仍為全部字符串。 說明 gets函數(shù)并不以空格作為字符串輸入結(jié)束的標(biāo)志, 而只以回車作為輸入結(jié)束。這是與 scanf函數(shù)不同的。 結(jié)果: input string: BASIC BASIC 43 43 strcat 格式: strcat (字符數(shù)組名 1,字符數(shù)組名 2) 功能:把字符數(shù)組 2中的字符串連接到字符數(shù)組 1中字符串的后面,并刪去字符串 1后的串標(biāo)志 “ \0” 。本函數(shù)返回值是字符數(shù)組 1的首地址 include main() { static char st1[30]=My name is 。 char st2[10]。 printf(input your name:\n)。 gets(st2)。 strcat(st1,st2)。 puts(st1)。 } 本程序把初始化賦值的字符數(shù)組與動態(tài)賦值的字符串連接起來。 要注意的是,字符數(shù)組 1應(yīng)定義足夠的長度,否則不能全部裝入被連 接的字符串。 運(yùn)行結(jié)果 : input your name: Li Ming回車 My name is Li Ming 44 44 167。 字符數(shù)組 strcpy 格式: strcpy (字符數(shù)組名 1,字符數(shù)組名 2) 功能:把字符數(shù)組 2中的字符串拷貝到字符數(shù)組 1中。串結(jié)束標(biāo)志“ \0” 也一同拷貝。字符數(shù)組名 2, 也可以是一個字符串常量。這時相當(dāng)于把一個字符串賦予一個字符數(shù)組。 include main() { static char st1[15],st2[]=C Language。 strcpy(st1,st2)。 puts(st1)。printf(\n)。 } 本函數(shù)要求字符數(shù)組 1應(yīng)有足夠的長度,否則不能全部裝入所拷 貝的字符串。 運(yùn)行結(jié)果 : C Language 45 45 167。 字符數(shù)組 strcmp 格式: strcmp(字符數(shù)組名 1,字符數(shù)組名 2) 功能:按照 ASCII碼順序比較兩個數(shù)組中的字符串,并由函數(shù)返回值返回比較結(jié)果。 字符串 1=字符串 2,返回值= 0; 字符串 1〉字符串 2,返回值〉 0; 字符串 1〈字符串 2,返回值〈 0。 本函數(shù)也可用于比較兩個字符串常量,或比較數(shù)組和字符串常量。 46 46 167。 字符數(shù)組 include main() { int k。 static char st1[15],st2[]=C Language。 printf(input a string:\n)。 gets(st1)。 k=strcmp(st1,st2)。 if(k==0) printf(st1=st2\n)。 if(k0) printf(st1st2\n)。 if(k0) printf(st1st2\n)。 } 本程序中把輸入的字符串和數(shù)組 st2中的串比較,比較結(jié)果返回到 k中,根據(jù) k值再輸出結(jié)果提示串。 RUN 回車 input a string: BASIC Language回車 st1st2 RUN 回車 input a string: dBASE Language回車 st1st2 RUN 回車 input a string: C Language回車 st1=st2 47 47 167。 字符數(shù)組 strlen 格式: strlen(字符數(shù)組名 ) 功能:測字符串的實際長度 (不含字符串結(jié)束標(biāo)志‘ \0’ ) 并作為函數(shù)返回值 include main() { int k。 static char st[]=C language。 k=strlen(st)。 printf(The length of the string is %d\n,k)。 } 運(yùn)行結(jié)果 : The length of the string is 10 48 48 小 結(jié) ? 1、數(shù)組的定義與引用; ? 2、字符數(shù)組和字符串; ? 利用數(shù)組進(jìn)行相關(guān)程序的設(shè)計。 ? 重點:利用數(shù)組進(jìn)行相關(guān)程序的設(shè)計如排序、查找、二 維表格的處理、矩陣運(yùn)算等。 49 49 作 業(yè) ? 書面作業(yè) – P118 、 、 (畫流程圖和 NS圖 ) ? 上機(jī)作業(yè) – 實驗六 ? 課外上機(jī)作業(yè) – 本章的所有例題、習(xí)題
點擊復(fù)制文檔內(nèi)容
研究報告相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1