字符串中的一些基本操作函数(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 ...
随机推荐
- 【转】 JSONObject使用方法
随笔- 46 文章- 0 评论- 132 JSONObject简介 本节摘要:之前对JSON做了一次简单的介 绍,并把JSON和XML做了一个简单的比较:那么,我就在想,如果是一个json格式的字 ...
- iOS 利用self.navigationItem.backBarButtonItem修改后退按钮文字
@property(nonatomic,retain) UIBarButtonItem *backBarButtonItem; // Bar button item to use for the ba ...
- iOS 定制controller过渡动画 ViewController Custom Transition使用体会
最近学习了一下ios7比较重要的一项功能,就是 controller 的 custom transition. 在ios7中,navigation controller 中就使用了交互式过渡来返回上级 ...
- JavaScript设计模式 - 代理模式
代理模式是为一个对象提供一个代用品或占位符,以便控制对它的访问 代理模式的用处(个人理解):为了保障当前对象的单一职责(相对独立性),而需要创建另一个对象来处理调用当前对象之前的一些逻辑以提高代码的效 ...
- c++ template函数的声明和实现需要在同一个文件中
新建一个class C;生成2个文件C.h和C.cpp,在C.h中声明一个函数 template<class T> T stringTo(char* str); 直接用VAssistX的R ...
- icon上添加数字提醒
使用viewbadger包: package com.jingle.vierbagerstudy; import android.app.Activity; import android.os.Bun ...
- unix/linux进程详解——代码
#include <iostream>#include <vector>#include <cstdint>#include <cstring>#inc ...
- 一、HTML和CSS基础--HTML+CSS基础课程--第1部分
第一章 HTML介绍 Html和CSS的关系 1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2. CSS样式是表现.就像网页的外衣.比 ...
- 图解SQL的inner join、left join、right join、full outer join、union、union all的区别
SQL的Join语法有很多,inner join(等值连接) 只返回两个表中联结字段相等的行,left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录,right join(右 ...
- .net学习之多线程、线程死锁、线程通信 生产者消费者模式、委托的简单使用、GDI(图形设计接口)常用的方法
1.多线程简单使用(1)进程是不执行代码的,执行代码的是线程,一个进程默认有一个线程(2)线程默认情况下都是前台线程,要所有的前台线程退出以后程序才会退出,进程里默认的线程我们叫做主线程或者叫做UI线 ...