1、字符串反转 – strRev

void strRev(char *str)
{
assert(NULL != str);
 
    int length=strlen(str);
char *end=str+length-1; while(end > str)
{
*str=(*str)^(*end);
*end=(*str)^(*end);
*str=(*str)^(*end); end--;
str++;
}
}

2、字符串复制 – strcpy

char *strcpy(char *strDest, const char *strStr)
{
assert((NULL != strDest) && (NULL != strStr)); char *Dest=strDest; while((*Dest++)=(*strStr++))
{} return strDest;
}

3、字符串拼接 –strcat

char *strcat(char *strDest, const char *strStr)
{
assert((NULL != strDest) && (NULL != strStr)); int length=strlen(strDest); char *Dest=strDest+length; while((*Dest++)=(*strStr++))
{} return strDest;
}

4、字符串比较 –strcmp

int strcmp(const char *strDest, const char *strStr)
{
assert((NULL != strDest) && (NULL != strStr)); while(0==(*strDest - *strStr) && *strDest )
{
strDest++;
strStr++;
} if(*strDest > *strStr)
return 1;
else if(*strDest < *strStr)
return -1;
else
return 0;
}

5、字符串长度 –strlen

int strlen(const char *strStr)
{
assert(NULL != strStr); int length = 0; while('\0' != *strStr)
{
length++;
strStr++;
} return length;
}

6、字符串转数字 –atoi

int atoi(const char *strStr)
{
assert(NULL != strStr); int minus = 0;
int begin = 0;
int sum = 0; while('\0' !=*strStr)
{
if(0==begin && (isdigit(*strStr) || '+'==*strStr || '-'==*strStr))
{
begin = 1; if('-'==*strStr)
{
minus = 1;
strStr++;
continue;
}
}
else if(!isdigit(*strStr))
{
printf("format is wrong !\n");
exit(1);
} if(1==begin)
{
sum = sum*10 + (*strStr-'0');
} strStr++;
} return minus ? (-sum):(sum);
}

7、数字转字符串 –atoi

char *itoa(int num)
{
int temp,i,j;
char array[10];
static char strDest[10]; for(temp = num,i=0; i<10 && temp ;i++)
{
array[i]=temp%10+'0';
temp/=10;
} for(i=i-1,j=0 ; i>=0 && j<10; i--,j++)
{
strDest[j]=array[i];
}
strDest[j]='\0'; return strDest;
}

8、计算字符串中元音字符的个数

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<ctype.h> int isVowel(char letter)
{
switch(toupper(letter))
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return 1;
default:
return 0;
}
} int countVowel(const char * strStr)
{
assert(NULL != strStr); int count=0; while('\0' !=*strStr++)
{
if(isVowel(*strStr))
count++;
} return count;
} int main()
{
char a[10]="hwlulr"; printf("%d\n",countVowel(a)); return 0;
}

9、判断一个字符串是否是回文

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#include<ctype.h> int isEqual(char a,char b)
{
if(a==b)
return 1; return 0;
} int isPalindrome(const char * strStr)
{
assert(NULL != strStr); int length=strlen(strStr);
int i,j; for(i=0,j=length-1; i<j ; i++,j--)
{
/*跳过空格和符号*/
while(' '== *(strStr+i) || !isalpha(*(strStr+i)))
i++;
while(' '== *(strStr+j) || !isalpha(*(strStr+j)))
j--; if(0==isEqual(*(strStr+i),*(strStr+j)))
return 0;
} return 1;
} int main()
{
char a[10]="heo o, e h"; printf("%s\n",isPalindrome(a) ? "is Palindrome" : "is not Palindrome"); return 0;
}

C语言字符串操作函数实现的更多相关文章

  1. 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...

  2. C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    原文:http://www.cnblogs.com/JCSU/articles/1305401.html C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. ...

  3. C语言字符串操作函数整理

    整理C语言字符串相关的函数,以程序方式验证,以注释方式做说明. #include<stdio.h> #include<string.h> #include<stdlib. ...

  4. C语言字符串操作函数

    1.函数名: stpcpy  功  能: 拷贝一个字符串到另一个  用  法: char *stpcpy(char *destin, char *source);  程序例: #include < ...

  5. C语言字符串操作函数总结

    转载来源:https://blog.csdn.net/qq_33757398/article/details/81212618 字符串相关操作头文件:string.h 1.strcpy函数 原型:st ...

  6. C语言-字符串操作函数

    gets(char buffer[]) 从标准输入读取一行, 并去掉换行符, 在字符串末尾增加 '\0' 字符, 写入到缓冲区 成功则返回 buffer 的地址, 出错或者遇到文件结尾则返回空指针, ...

  7. c语言字符串操作大全

     C语言字符串操作函数 函数名: strcpy 功  能: 拷贝一个字符串到另一个 用  法: char *stpcpy(char *destin, char *source); 程序例: #incl ...

  8. C语言的常用字符串操作函数(一)

    一直做的是单片机相关的程序设计,所以程序设计上更偏向底层,对于字符串的操作也仅限于液晶屏幕上的显示等工作,想提高下字符串操作的水平,而不是笨拙的数组替换等方式,翻看帖子发现C语言的字符串操作函数竟然这 ...

  9. C语言字符串操作总结大全(超详细)

    本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作  strcpy(p, p1) 复制字符串  strncpy(p, p1, n) 复制指定长度字符串  strcat( ...

随机推荐

  1. border-radius bug 收集

    border-radius我相信对于老一辈的前端们有着特殊的感情,在经历了没有圆角的蛮荒时代,到如今 CSS3 遍地开花,我们还是很幸福的. 然而即使到了三星大脸流行时代,border-radius在 ...

  2. HTML5进阶

    内容: 1.geolocation元素 2.video元素和audio元素 3.localStorage 4.WebWorker 5.WebSQL.IndexedDB 6.文件操作.文件拖拽新概念 7 ...

  3. python中发布订阅和主从配置

    发布订阅 发布者不是计划发送消息给特定的接收者(订阅者),而是发布的消息分到不同的频道,不需要知道什么样的订阅者订阅 订阅者对一个或多个频道感兴趣,只需接收感兴趣的消息,不需要知道什么样的发布者发布的 ...

  4. jpa summary

    JPA Prepared by: John Tan March, Contents what Where to use JPA Difference between JPA and Mybatis 1 ...

  5. thymeleaf的使用

    1.导包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  6. Eclipse创建Maven-Web项目及解决 jre版本和web.xml版本问题

    eclipse maven-web有个蛋疼的问题,就是web版本很低. 且看别人是如何解决的:Eclipse创建Maven-Web项目及解决 jre版本和web.xml版本问题

  7. 机器学习入门-线性判别分析(LDA)1.LabelEncoder(进行标签的数字映射) 2.LinearDiscriminantAnalysis (sklearn的LDA模块)

    1.from sklearn.processing import LabelEncoder 进行标签的代码编译 首先需要通过model.fit 进行预编译,然后使用transform进行实际编译 2. ...

  8. mysql find_in_set排序

    假若有给定id数组(1,9,3,5,6);查询sql语句需要安装这个顺序排序 select * from tb where id in (1,9,3,5,6) order by find_in_set ...

  9. 转载:canal数据库同步redis

    ref: http://blog.csdn.net/tb3039450/article/details/53928351

  10. DateFormat工具类

    import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java. ...