C语言库函数的实战之一
生活随笔
收集整理的這篇文章主要介紹了
C语言库函数的实战之一
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//-1:strtok()函數
#include<stdio.h>
#include<string.h>int main(void)
{char buf[]="hello#world#today";//即將被分割的字符串char *temp = strtok(buf,"#");while(temp){printf("%s ",temp);temp = strtok(NULL,"#");}printf("\n");
return 0;}
//-2:strrchr() #include <string.h> #include <stdio.h> void main() {char * pCh = "www.inkcool.com";char * pFind = strrchr(pCh, '.');//找出點.最后一次出現在pCH的位置if ( pFind != NULL){printf("%s", pFind); //可以直接printf(pFind);printf("/n");左邊的表達式是合二為一的表達方法;}printf("\n"); }
//-3:strpbrk():返回兩個字符串中首個相同字符的位置 #include<stdio.h> #include<string.h> int main(void){char* s1 = "http://see.xidian.edu.cn/cpp/u/xitong/";//在C語言中,用指針形式來定義未知長度的字符串char* s2 = "see";char* p = strpbrk(s1,s2);if(p){printf("The result is: %s\n",p); }else{ //-4:strlen()返回字符串的長度 #include<stdio.h> #include<string.h>int main(void) {char* str1 = "zheng chaobing";printf("strlen(str1)=%d",strlen(str1));return 0;}
printf("Sorry!\n"); } return 0; }
轉載于:https://www.cnblogs.com/ZZiz/p/7622212.html
總結
以上是生活随笔為你收集整理的C语言库函数的实战之一的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Apache Kafka:大数据的实时处
- 下一篇: 查看HTTP请求返回状态码对照表详解