字符串中的一些基本操作函数(c语言)
其中很多函数返回的都是首地址,程序中只是将该地址后的内容全部输出来了。。。并没有作特殊处理输出地址。。。还有几个函数有点小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语言)的更多相关文章
- 三种java 去掉字符串中的重复字符函数
三种java 去掉字符串中的重复字符函数 public static void main(string[] args) { system.out.println(removerepeatedchar( ...
- php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpos
php字符串查找函数 php查找字符串中出现的次数函数substr_count,判断字符串中是否包含另一个字符串函数strpossubstr_count($haystack, $needle [,$o ...
- PHP实现删除字符串中任何字符的函数
function delStr($start, $end, $orgenStr) { //读取要删除字符位置的前一部分字符串,并赋值给$temp //strpos读取字符第一次出现的位置 //subs ...
- SAS中的剔除空格函数
left函数: 刪除字符串左边(开头> 的空格right函数: 刪除字符串右边(结尾> 的空格trim函数: 刪除字符串右边(结尾> 的空 ...
- java之字符串中查找字串的常见方法
1.int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引. int indexOf(String str, int startIndex):从指定 ...
- oracle查找某个字符在字符串中的个数的技巧
Oracle没有提供查找某个字符在字符串中出现次数的函数,当遇到这样的需求的时候,我们只能使用另外的方法去实现. 简单的思路就是,假设有个字符串str,然后里面有n个[a]字符,当把这n个[a]字符去 ...
- C语言函数sscanf()的用法-从字符串中读取与指定格式相符的数据(转)
C语言函数sscanf()的用法 sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var ...
- C语言strchr()函数:查找某字符在字符串中首次出现的位置
头文件:#include <string.h> strchr() 用来查找某字符在字符串中首次出现的位置,其原型为: char * strchr (const char *str, ...
- C语言strstr()函数:返回字符串中首次出现子串的地址
今天又学到了一个函数 头文件:#include <string.h> strstr()函数用来检索子串在字符串中首次出现的位置,其原型为: char *strstr( char *s ...
随机推荐
- php接口和多态的概念以及简单应用
接口是面向对象中的一个重要特性,也是面向对象开发不可缺少的一个概念,下面简单说一下接口的概念,先看一段简单的代码: interface ICanEat { public function eat($f ...
- 【USACO】namenum
//开始傻×了 受题目形容的误导 一心想生成所有可能的 字符串组合 之后查找非常慢 //听了同学的 将5000个dict里的字符串 转换成char型数组(不能直接用int 会越界)直接用输入的数据对着 ...
- [MAC] SVN lock的使用
转载 : http://www.eefocus.com/czzheng/blog/12-03/245532_4ca94.html 如果压根没有锁lock,那么每个人都拥有一个本地copy,每个人都能自 ...
- WebStorm设置字体和颜色
新建Scheme + 修改字体 ctrl+alt+s打开Settings界面,Editor > Colors&Fonts > Font. Default scheme是亮色调,但我 ...
- rdesktop remember
整个地球都知道rdesktop,有了它,我们可以从Solaris或者Linux使用Windows,当然Windows要开启Windows Terminal Service.虽然也有基于GTK+的tsc ...
- vm 负责虚拟机出现“”适配器 的mac地址在保留地址范围内‘’
我自己在windows中文件中,直接将一个虚拟机进行复制了一份,后用vm打开, 选择我已经移到,结果会出现了一下的情况, 导致了我无法ping 通,故我看到一下提示: 原来是我两台虚拟机的MaC ,即 ...
- /etc/profile和$HOME/.bash_profile
Linux中含有两个重要的文件 /etc/profile和$HOME/.bash_profile 每当系统登陆时都要读取这两个文件,用来初始化系统所用到的变量,其中/etc/profile是超级用户所 ...
- 如何从Apache官网下载windows版apache服务器
参考文章:http://jingyan.baidu.com/article/29697b912f6539ab20de3cf8.html
- 实例讲解虚拟机3种网络模式(桥接、nat、Host-only)
转自:http://www.cnblogs.com/ggjucheng/archive/2012/08/19/2646007.html 前言 很多人安装虚拟机的时候,经常遇到不能上网的问题,而vmwa ...
- kinect学习笔记(三)——深度数据的提取
一.创建Console工程 二.添加kinect引用 里面用引用,打开后 选择然后OK. 三.编写代码(有附加注释) using System; using System.Collections.Ge ...