亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C,C++中常用的操作字符串的函數(shù)

 更新時(shí)間:2017年09月14日 23:35:59   投稿:mdxy-dxy  
這篇文章主要介紹了C,C++中常用的操作字符串的函數(shù),需要的朋友可以參考下

小小的做一個(gè)總結(jié)
函數(shù)名: stpcpy
功 能: 拷貝一個(gè)字符串到另一個(gè),遇到'\0'時(shí)停止拷貝,destin要有足夠大的空間
用 法: char *stpcpy(char *destin, char *source);
 
函數(shù)名: strcat
功 能: 字符串拼接函數(shù),注意,destin要有足夠大的空間
用 法: char *strcat(char *destin, char *source);

函數(shù)名: strchr
功 能: 在一個(gè)串中查找給定字符的第一個(gè)匹配之處,找不到返回NULL
用 法: char *strchr(char *str, char c);
 
函數(shù)名: strcmp
功 能:  字符串大小比較,str1>str2 返回1,str1<str2 返回-1,相等返回0
用 法: int strcmp(char *str1, char *str2);
 
函數(shù)名: strncmpi
功 能: 比較字符串str1和str2的前maxlen個(gè)字符,忽略大小寫
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
 
函數(shù)名: strcpy
功 能: 遇到'\0'時(shí)停止拷貝,destin要有足夠大的空間
用 法: char *strcpy(char *str1, char *str2);
 
函數(shù)名: strcspn
功 能: 返回字符串s1中第一個(gè)在s2中出現(xiàn)的字符在s1中的下標(biāo)值,亦即在s1中出現(xiàn)而s2中沒有出現(xiàn)的子串的長(zhǎng)度
用 法: int strcspn(char *str1, char *str2);
程序例:
str1="Golden Global View"; str2 = "new"
在s1中,且在s2中, n e  w這三個(gè)字符都滿足,而e是在s1中最先出現(xiàn)的,所以返回它的位置

函數(shù)名: strdup
功 能: 將串拷貝到新建的位置處,注意,在使用該函數(shù)時(shí),申請(qǐng)了一片新的內(nèi)存,所以使用后必須釋放
用 法: char *strdup(char *str);
程序例:

#include <stdio.h>
#include <string.h>
#include <alloc.h>
int main(void)
{
  char *dup_str, *string = "abcde";
  dup_str = strdup(string);	// 申請(qǐng)了一片新的內(nèi)存地址,dup_str指向了這片內(nèi)存
  printf("%s\n", dup_str);
  free(dup_str);		// 一定要釋放
  return 0;
}

函數(shù)名: stricmp
功 能: 比較字符串大小,忽略大小寫
用 法: int stricmp(char *str1, char *str2);

函數(shù)名: strerror
功 能: 返回指向錯(cuò)誤信息字符串的指針
用 法: char *strerror(int errnum);
程序例:

#include <stdio.h>
#include <errno.h>
int main(void)
{
  char *buffer;
  buffer = strerror(errno);
  printf("Error: %s\n", buffer);
  return 0;
}

函數(shù)名: strcmpi
功 能: 比較兩個(gè)字符串,忽略大小寫
用 法: int strcmpi(char *str1, char *str2);

函數(shù)名: strncmp
功 能: 比較字符串大小  maxlen是比較的位數(shù)
用 法: int strncmp(char *str1, char *str2, int maxlen);

函數(shù)名: strncmpi
功 能: 把串中的一部分與另一串中的一部分比較, 不管大小寫,maxlen是比較的位數(shù)
用 法: int strncmpi(char *str1, char *str2,int maxlen);

函數(shù)名: strncpy
功 能: 串拷貝  maxlen規(guī)定拷多少位
用 法: char *strncpy(char *destin, char *source, int maxlen);

函數(shù)名: strnicmp
功 能: 忽略大小寫比較字符串  maxlen是比較的位數(shù)
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
 
函數(shù)名: strnset
功 能: 將一個(gè)字符串中的前n個(gè)字符都設(shè)為指定字符ch
用 法: char *strnset(char *str, char ch, unsigned n);
 
函數(shù)名: strpbrk
功 能: 在源字符串(s1)中找出最先含有搜索字符串(s2)中任一字符的位置并返回,若找不到則返回空指針
用 法: char *strpbrk(char *str1, char *str2);
 
函數(shù)名: strrchr
功 能: 在串中查找指定字符的最后一個(gè)出現(xiàn)
用 法: char *strrchr(char *str, char c);
 
函數(shù)名: strrev
功 能: 串倒轉(zhuǎn)
用 法: char *strrev(char *str);

函數(shù)名: strset
功 能: 將一個(gè)串中的所有字符都設(shè)為指定字符
用 法: char *strset(char *str, char c);
 
函數(shù)名: strspn
功 能: 返回字符串str1中第一個(gè)不在指定字符串str2中出現(xiàn)的字符下標(biāo)
用 法: int strspn(char *str1, char *str2);
 
函數(shù)名: strstr
功 能: 在串中查找指定字符串的第一次出現(xiàn)
用 法: char *strstr(char *str1, char *str2);
 
函數(shù)名: strtok
功 能: 查找由在第二個(gè)串中指定的分界符分隔開的單詞
用 法: char *strtok(char *str1, char *str2);
程序例:

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
  char sentence[]="This is a sentence with 7 tokens";
  cout<< "The string to be tokenized is:\n"<< sentence <<"\n\nThe tokens are:\n\n";
  char *tokenPtr=strtok(sentence," ");
  while(tokenPtr!=NULL)
	{
    cout<<tokenPtr<<endl;
    tokenPtr=strtok(NULL," "); // 再次調(diào)用時(shí),第一個(gè)參數(shù)傳NULL
  }
  
}

函數(shù)名: strupr
功 能: 將串中的小寫字母轉(zhuǎn)換為大寫字母
用 法: char *strupr(char *str);

函數(shù)名: swab
功 能: 交換字節(jié) ,nbytes是交換的字節(jié)數(shù)
用 法: void swab (char *from, char *to, int nbytes);
程序例:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char source[15] = "Frank Borland";
char target[15];
int main(void)
{
  swab(source, target, strlen(source));
  printf("This is target: %s\n", target);
  return 0;
}

到此就結(jié)束了,大家可以查看下面的幾篇文章。

相關(guān)文章

  • C++ 中的Swap函數(shù)寫法匯總

    C++ 中的Swap函數(shù)寫法匯總

    這篇文章主要介紹了C++ 中的Swap函數(shù)寫法匯總,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • c++中的自增/自減操作方式

    c++中的自增/自減操作方式

    這篇文章主要介紹了C++中的自增和自減運(yùn)算符,包括前綴和后綴形式,并通過一個(gè)具體的例子解釋了自增/自減表達(dá)式的值與函數(shù)參數(shù)傳遞的關(guān)系,文章指出,自增/自減表達(dá)式的值是在表達(dá)式求值時(shí)確定的,而不是在自增/自減運(yùn)算后
    2025-03-03
  • C++ HTTP框架推薦(特點(diǎn)及優(yōu)勢(shì))

    C++ HTTP框架推薦(特點(diǎn)及優(yōu)勢(shì))

    這篇文章主要介紹了C++ HTTP框架推薦的相關(guān)資料,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2025-05-05
  • C語言數(shù)據(jù)結(jié)構(gòu)旋轉(zhuǎn)鏈表的實(shí)現(xiàn)

    C語言數(shù)據(jù)結(jié)構(gòu)旋轉(zhuǎn)鏈表的實(shí)現(xiàn)

    這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu)旋轉(zhuǎn)鏈表的實(shí)現(xiàn)的相關(guān)資料,這里提供實(shí)例幫助大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下
    2017-08-08
  • C語言中的結(jié)構(gòu)體內(nèi)嵌函數(shù)用法

    C語言中的結(jié)構(gòu)體內(nèi)嵌函數(shù)用法

    這篇文章主要介紹了C語言中的結(jié)構(gòu)體內(nèi)嵌函數(shù)用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • VC6.0如何創(chuàng)建以及調(diào)用動(dòng)態(tài)鏈接庫實(shí)例詳解

    VC6.0如何創(chuàng)建以及調(diào)用動(dòng)態(tài)鏈接庫實(shí)例詳解

    作為客戶與后臺(tái)的中介,為了更好的調(diào)節(jié)兩方的關(guān)系,我明智滴選擇了webservice以及動(dòng)態(tài)鏈接庫。在與客戶c++使動(dòng)態(tài)鏈接庫方式,而與后臺(tái)java,使用webservice來交流溝通
    2013-01-01
  • 詳解C#byte數(shù)組怎么傳入C

    詳解C#byte數(shù)組怎么傳入C

    在本篇內(nèi)容里小編給大家整理了關(guān)于C#byte數(shù)組怎么傳入C的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)參考下。
    2019-03-03
  • 詳解C++中的isunordered函數(shù)

    詳解C++中的isunordered函數(shù)

    這篇文章主要介紹了C++中的isunordered函數(shù),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • 詳解C++11 變參模板

    詳解C++11 變參模板

    這篇文章主要介紹了C++11 變參模板的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)c++11,感興趣的朋友可以了解下
    2020-08-08
  • 深入理解鏈表的各類操作詳解

    深入理解鏈表的各類操作詳解

    本篇文章是對(duì)鏈表的各類操作進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05

最新評(píng)論