字符串中的一些基本操作函数(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 字符串负值判断
2014年9月9日 11:54:54 $a = '-1'; $b = (int)$a; $c = is_numeric($a); if ($a) { echo 1; //echo 1 } else { ...
- After Effects的4种抠像插件比较分析
前景 背景 1.keylight(1.2) 2.Primatee Keyer Pro4.0 3.Zbig [边界生硬] 4.Power Matte v2 [速度很慢,边界生硬]
- Java for LeetCode 045 Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Java for LeetCode 031 Next Permutation
Next Permutation Total Accepted: 33595 Total Submissions: 134095 Implement next permutation, whi ...
- JavaEE面试题库
Java EE软件工程师 认证考试 面试题大全 目 录 第一部分 HTML/CSS/JavaScript 1 1. HTML含义和版本变化... 1 2. ...
- [编解码] 关于base64编码的原理及实现
转载自: http://www.cnblogs.com/hongru/archive/2012/01/14/2321397.html [Base64]-base64的编码都是按字符串长度,以每3个8b ...
- Linux使用tcpdump命令抓包保存pcap文件wireshark分析
[root@ok Desktop]# yum search tcpdump Loaded plugins: fastestmirror, refresh-packagekit, security Lo ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem B: Minesweeper(模拟扫雷)
Problem B: Minesweeper Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 29 Solved: 7[Submit][Status][W ...
- acm常用术语
OJ是Online Judge系统的简称,用来在线检测程序源代码的正确性. Accepted (AC) : OK! Your program is correct! Presentation Erro ...
- 解决treeview未选中时,默认选中首个根节点的问题!
private void treeView1_MouseUp(object sender, MouseEventArgs e) { TreeNode selectnode = this.treeVie ...