下载此文档

string源代码.docx


文档分类:IT计算机 | 页数:约6页 举报非法文档有奖
1/6
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/6 下载此文档
文档列表 文档介绍
S tring 1. strlen(), 计算字符串长度 int strlen(const char string) { int i=0; while(string[i]) i++; return i;} 2. strcpy(), 字符串拷贝. char *strcpy(char *destination, const char *source) { while(*destinaton++=*source++); return (destination-1); } 3. strcat(), 字符串的连接. char *strcat(char *target,const char *source) { char *original=target; while(*target) target++; // Find the end of the string while(*target++=*source++); return(original); } 4. streql(), 判断两个字符串是否相等. int streql(char *str1,char *str2) { while((*str1==*str2)&&(*str1)) { str1++; str2++; } return((*str1==NULL)&&(*str2==NULL)); } 5. strchr(), 在字符串中查找某个字符. char *strchr(const char *string,int letter) { while((*string!=letter)&(*string)) string++; return (string); } 6. t(), 计算某个字符在字符串中出现的次数. int t(const char *string,int letter) { int count=0; while(*string) if(*string==letter)count++; return count; } 7. strcmp(), 判断两个字符串是否相等. int strcmp(const char *str1,const char *str2) { while((*str1==*str2)&&(*str1)) { str1++; str2++; } if((*str1==*str2)&&(!*str1)) //Same strings return o; else if((*str1)&&(!*str2)) //Same but str1 longer return -1; else if((*str2)&&(!*str1)) //Same but str2 longer else return((*str1>*str2)?-1:1); }二. String 类 1. int size(string str) { //return the size ofa string int count = 0; while (str[count]) { count++; } return count; }2. bool empty(string str) { //check whether a string is empty or not bool empty

string源代码 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数6
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xxj16588
  • 文件大小0 KB
  • 时间2016-03-19