C字元与字串.pptVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
C字元与字串.ppt

第十一章 字串與字元庫存函數 字串庫存函數 字串庫存函數 定義在string.h標頭檔中,因此在使用時必須將此標頭檔包含到程式中 常見的庫存函數 strlen() strcpy() strcat() strcmp() strchr()…等等 字串庫存函數 strlen 函數 此函數主要是用來計算字串的長度 語法如下: strlen(s); 此函數會計算s字串的長度 範例ex11-1a.c 字串庫存函數 /* File name: ex11-1a.c */ #include stdio.h #include string.h #include stdlib.h int main() { char *s = computer; printf(The length of %s = %d, s, strlen(s)); } 字串庫存函數 strcpy 函數 此函數主要是用來做字串的拷貝 語法如下: strcpy(t, s); 此函數會將 s 字串拷貝到 t 字串,注意 s 字串的內容將不會被更動 範例ex11-1b.c 字串庫存函數 /* File name: ex11-1b.c */ #include stdio.h #include string.h #include stdlib.h int main() { char *s = computer; char t[80] = printer; printf(Before strcpy(t, s)\n); printf(s = %s\n, s); printf(t = %s\n, t); printf(After strcpy(t, s)\n); strcpy(t, s); printf(s = %s\n, s); printf(t = %s\n, t); } 字串庫存函數 strcat 函數 此函數主要是用來做字串的連結 語法如下: strcat(t, s); 此函數會將 s 字串連接在 t 字串之後,最後 t 字串會增長,而 s 字串不變 範例ex11-1c.c 字串庫存函數 /* File name: ex11-1c.c */ #include stdio.h #include string.h #include stdlib.h int main() { char *s = computer; char t[80] = PC ; printf(Before strcat(t, s)\n); printf(s = %s\n, s); printf(t = %s\n, t); printf(After strcat(t, s)\n); strcat(t, s); printf(s = %s\n, s); printf(t = %s\n, t); } 字串庫存函數 strcmp 函數 此函數主要是比較兩個字串,其比較標準是將兩個字串逐一相比,利用字元所對應的ASCII碼做比較 其語法如下: strcmp(t, s); 此函數會將 t 字串和 s 字串相比較 範例ex11-1d.c 字串庫存函數 字串比較情形如下: 當兩字串相等時,得到的值為0 當 t 字串大於 s 字串時,得到的答案是 0 當 t 字串小於 s 字串時,得到的答案是 0 字串庫存函數 /* File name: ex11-1d.c */ #include stdio.h #include string.h #include stdlib.h int main() { char *s = computer; char *t = computer; printf(strcmp(%s, %s) = %d\n, t, s, strcmp(t, s)); t = company; printf(strcmp(%s, %s) = %d\n, t, s, strcmp(t, s)); t = content; printf(strcmp(%s, %s) = %d\n, t, s, strcmp(t, s)); } 字串庫存函數 strncpy 函數 此函數之功能同strcpy(),但只拷貝n個字串,其中n為整數 其語法如下: strncpy(t, s, n); 此函數會拷貝 n 個字元到 t 字串 範例ex11-1e.c 字串庫存函數 /* File name: ex11-1e.c */ #include stdio

文档评论(0)

2752433145 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档