其中很多函数返回的都是首地址,程序中只是将该地址后的内容全部输出来了。。。并没有作特殊处理输出地址。。。还有几个函数有点小bug。

#include"iostream"
#include"stdio.h"
#include"string.h"
#define mx 100
using namespace std;
int main()
{
char str1[mx],str2[mx];
cout<<"strcpy字符串拷贝函数:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
strcpy(str1,str2);
cout<<str1<<endl<<endl;
cout<<"strncpy字符串部分复制函数:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
strncpy(str1,str2,);
cout<<str1<<endl<<endl;
cout<<"strcat字符串连接:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
strcat(str1,str2);
cout<<str1<<endl<<endl;
cout<<"strncat将特定数量的字符串连接到另一个字符串:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
strncat(str1,str2,);
cout<<str1<<endl<<endl;
/* cout<<"_strdup预先配置内存,将字符串存入该内存里:"<<endl;
cout<<str1<<endl<<endl;
cout<<"输入字符串2:";
cin>>str2;
str1=_strdup(str2);
cout<<str1<<endl<<endl; */
cout<<"strchr在给定字符串中搜索指定字符:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
char *p=strchr(str1,'e');
cout<<p[]<<endl<<endl;
/* cout<<"strcspn在给定字符串中搜索某个指定字符第一次出现的位置:"<<endl;
cout<<"输入字符串2:";
cin>>str2;
int position=strcspn(str2,'r');
cout<<position<<endl<<endl;*/
cout<<"strrchr在给定字符串中搜索某个指定字符最后一次出现的地址:"<<endl;
cout<<"输入字符串2:";
cin>>str2;
char *lastp=strrchr(str2,'l');
cout<<lastp<<endl<<endl;
cout<<"strpbrk在两个字符串中寻找首次共同出现的字符:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
char *p=strpbrk(str1,str2);
cout<<p[]<<endl<<endl;
cout<<"strstr在两个字符串中寻找首次共同出现的公共子字符串:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
cout<<strstr(str1,str2)<<endl<<endl;
cout<<"strlen计算字符串的长度:"<<endl;
cout<<"输入字符串2:";
cin>>str2;
cout<<strlen(str2)<<endl<<endl;
cout<<"_strnset在给定的字符串中按指定数目将若干字符置换为指定字符:"<<endl;
cout<<"输入字符串2:";cin>>str2;
strnset(str2,,'$');
cout<<str2<<endl<<endl;
cout<<"strcmp比较字符串大小:"<<endl;
cout<<"输入字符串1:";
cin>>str1;
cout<<"输入字符串2:";
cin>>str2;
cout<<strcmp(str1,str2)<<endl;
return ;
}

字符串中的一些基本操作函数(c语言)的更多相关文章

  1. 三种java 去掉字符串中的重复字符函数

    三种java 去掉字符串中的重复字符函数 public static void main(string[] args) { system.out.println(removerepeatedchar( ...

  2. php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos

    php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...

  3. PHP实现删除字符串中任何字符的函数

    function delStr($start, $end, $orgenStr) { //读取要删除字符位置的前一部分字符串,并赋值给$temp //strpos读取字符第一次出现的位置 //subs ...

  4. SAS中的剔除空格函数

    left函数:         刪除字符串左边(开头> 的空格right函数:       刪除字符串右边(结尾> 的空格trim函数:         刪除字符串右边(结尾> 的空 ...

  5. java之字符串中查找字串的常见方法

    1.int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引.      int indexOf(String str, int startIndex):从指定 ...

  6. oracle查找某个字符在字符串中的个数的技巧

    Oracle没有提供查找某个字符在字符串中出现次数的函数,当遇到这样的需求的时候,我们只能使用另外的方法去实现. 简单的思路就是,假设有个字符串str,然后里面有n个[a]字符,当把这n个[a]字符去 ...

  7. C语言函数sscanf()的用法-从字符串中读取与指定格式相符的数据(转)

    C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var ...

  8. C语言strchr()函数:查找某字符在字符串中首次出现的位置

    头文件:#include <string.h> strchr() 用来查找某字符在字符串中首次出现的位置,其原型为:    char * strchr (const char *str, ...

  9. C语言strstr()函数:返回字符串中首次出现子串的地址

    今天又学到了一个函数 头文件:#include <string.h> strstr()函数用来检索子串在字符串中首次出现的位置,其原型为:    char *strstr( char *s ...

随机推荐

  1. javascript 布尔类型值判断

    javascript中,值非null的对象在if()中都会被判断为true: if([]) {// true} if({}) {// true} if(null) {// false} if(&quo ...

  2. jquery validate自定义checkbox验证规则和样式

    参考:http://blog.csdn.net/xh16319/article/details/9987847 自定义checkbox验证,“检查checkbox是否选中” jQuery.valida ...

  3. linux shell脚本守护进程监控svn服务

    最近搭建的svn服务不知道什么原因服务总是被关闭(如果你不知道怎么搭建svn可以参考linux下搭建svn版本控制软件),因此用shell脚本实现一个守护进程.用于监控svn服务是否启动,如果服务不在 ...

  4. 六间房 去掉水印的方法 绕过游客VIP限制

    firefox 40 + Adblock Plus 2.6.9.1 + Execute JS 0.2.4.1 Adblock Plus 过滤规则里添加 ------------------------ ...

  5. CStringUtf8ToUnicode

    CString CStringUtf8ToUnicode( CString Utf8 ) { int wLen = 0; CString strUnicode; LPSTR pBufChar = NU ...

  6. 一、HTML和CSS基础--网页布局--如何用css进行网页布局

    什么叫做布局? 又称版式布局,是网页UI设计师将有限的视觉元素进行有机的排列组合. 网页设计的特点 网页可以自适应宽度 网页的高度理论上可以无限延长 网页分栏 分栏又称为分列,常见的布局分为:一列布局 ...

  7. 昨天用的流量有点多60M

    就是因为值班这里没有无线,然后自己又是受前几次的影响,没有收到微信,然后就看了热点,这是用的快的.

  8. Redis笔记(一)Redis简介

    关于Redis Redis是一款开源的高性能键值对数据库,最初的作者是意大利的Salvatore Sanfilippo,他的github是 antirez ,Redis的源码同样托管在Git上:htt ...

  9. jQuery Mobile 基础(第四章)

    1.主题 jQuery Mobile 提供了5种不同的主题样式, 从 "a" 到 "e" - 每一种主题的按钮,工具条,内容块等等颜色都不一致,每个主题的视觉效 ...

  10. GRE红宝书5-6

    page5 adopt: adoration: adore:   --ore讲话, oration演讲 adorn:   orn表示装饰, ornate adulation:      adulate ...