數據結構常用的字符串函數(中英雙釋)

頭文件:string.h

1.strchr

const char * strchr ( const char * str, int character );
Locate first occurrence of character in string

str

C string.

character

Character to be located.

Return Value

A pointer to the first occurrence of? character? in? str .

If the?character?is not found, the function returns a null pointer.

2.strlen
function
<cstring>

strlen

size_t strlen ( const char * str );
Get string length

Return Value

Returns the length of the C string?str.
3.strcmp
char * strcpy ( char * destination, const char * source );
Copy string

Parameters

destination

Pointer to the destination array where the content is to be copied.

source

C string to be copied.

Return Value

destination ?is returned.
4.strcat
char * strcat ( char * destination, const char * source );
Concatenate strings? ? //追加字符串

Parameters

destination

Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string.

source

C string to be appended. This should not overlap?destination.

Return Value

destination ?is returned.
注:
源字符串必須以 '\0' 結束。
目標空間必須有足夠的大,能容納下源字符串的內容。
目標空間必須可修改。
5.strcmp
int strcmp ( const char * str1, const char * str2 );
Compare two strings

Parameters

str1

C string to be compared.

str2

C string to be compared.

Return Value

Returns an integral value indicating the relationship between the strings:
return value
indicates
<0
the first character that does not match has a lower value in? ptr1?than in? ptr2
0
the contents of both strings are equal
>0
the first character that does not match has a greater value in? ptr1?than in? ptr2
6.strncpy? :長度限制為num字節
char * strncpy ( char * destination, const char * source, size_t num );
Copy characters from string
7.strncat? :追加長度為n字節
char * strncat ( char * destination , const char * source , size_t num );
8.strncmp? :比較個數為n字節
9.strstr :查找子串
char * strstr ( const char * str1 , const char * str2 );
Returns a pointer to the first occurrence of str2 !!!in str1!!!, or a null pointer if str2 is not part of str1.
注意:返回的是在str1中的指針
10.strtok:截斷字符串、存在記憶功能
char * strtok ( char * str , const char * sep );
1.sep 參數是個字符串,定義了用作分隔符的字符集合
2.第一個參數指定一個字符串,它包含了 0 個或者多個由 sep 字符串中一個或者多個分隔符分割的標 記。
3. strtok 函數找到 str 中的下一個標記,并將其用 \0 結尾,返回一個指向這個標記的指針。(注:
strtok 函數會改變被操作的字符串,所以在使用 strtok 函數切分的字符串一般都是? ?!!! 臨時拷貝 !!!? ?的內容 并且可修改。)
4. strtok 函數的第一個參數不為 NULL ,函數將找到 str 中第一個標記, strtok 函數將保存它在字符串 中的位置,作為一個標記。
5 . strtok 函數的第一個參數為 NULL ,函數將在同一個字符串中被保存的位置開始,查找下一個標 記。
11.strerror
char * strerror ( int errnum );??
返回錯誤碼所對應的錯誤信息。(只是返回,不打印)
常結合errno這個全局變量使用(頭文件為errno.h)
errno記錄著錯誤碼
12.perror:打印錯誤碼對應的錯誤信息
#include <stdio.h>
#include <errno.h>
int main() {
FILE* file = fopen( "none.txt", "r");
if (file == NULL) {
perror( "Error");?? //打印為:Error: No such file or directory?????? //自動換行
perror( "Error fopen");?? //打印為:Error fopen: No such file or directory
return 1;
}
return 0;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/717952.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/717952.shtml
英文地址,請注明出處:http://en.pswp.cn/news/717952.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

適用于恢復iOS數據的 10 款免費 iPhone 恢復軟件

現在&#xff0c;您可以獲得的 iPhone 的存儲容量比大多數人的筆記本電腦和臺式電腦的存儲容量還要大。雖然能夠存儲數千張高分辨率照片和視頻文件、安裝數百個應用程序并隨身攜帶大量音樂庫以供離線收聽固然很棒&#xff0c;但在一個地方擁有如此多的數據可能會帶來毀滅性的后…

2.2_5 調度算法

文章目錄 2.2_5 調度算法一、適用于早期的批處理系統&#xff08;一&#xff09;先來先服務&#xff08;FCFS&#xff0c;First Come First Serve&#xff09;&#xff08;二&#xff09;短作業優先&#xff08;SJF&#xff0c;Shortest Job First&#xff09;&#xff08;三&a…

SpringMVC總結

SpringMVC SpringMVC是隸屬于Spring框架的一部分&#xff0c;主要是用來進行Web開發&#xff0c;是對Servlet進行了封裝。 對于SpringMVC我們主要學習如下內容: SpringMVC簡介 請求與響應 REST風格 SSM整合(注解版) 攔截器 SpringMVC是處理Web層/表現層的框架&#xff…

易語言源代碼5000例

僅供學習研究交流使用 加群下載

探索MyBatis-Plus的高階用法

引言 MyBatis-Plus 是 MyBatis 的增強工具包&#xff0c;提供了許多方便快捷的功能來簡化開發&#xff0c;提高效率。除了基本的 CRUD 操作外&#xff0c;MyBatis-Plus 還提供了一些高級功能&#xff0c;本文將探討 MyBatis-Plus 的高階用法&#xff0c;幫助開發者更好地利用該…

Linux服務器搭建超簡易跳板機連接阿里云服務器

簡介 想要規范內部連接阿里云云服務器的方式&#xff0c;但是最近懶病犯了&#xff0c;先搞一個簡易式的跳板機過渡一下&#xff0c;順便在出一個教程&#xff0c;其他以后再說&#xff01; 配置方法 創建密鑰 登錄阿里云&#xff0c;找到云服務器ECS控制臺&#xff0c;點擊…

【小白友好】LeetCode 打家劫舍 III

https://leetcode.cn/problems/house-robber-iii/description/ 前言 建議還是先看看動態規劃的基礎題再看這個。動態規劃是不刷題&#xff0c;自己100%想不出來的。 基礎題&#xff1a; 23 小白想法 現在我們想遍歷的數據結構不是數組了&#xff0c;而是一顆樹。在樹上的d…

C++遞推

統計每個月兔子的總數 #include<bits/stdc.h> using namespace std; int n,sum0; void f(int); int main() {int a[1000];cin>>n;a[1]1;a[2]2;for(int i3;i<1000;i){a[i]a[i-1]a[i-2];}cout<<a[n];return 0; } void f(int n){}猴子吃桃子 #include<b…

2024年華為OD機試真題-電腦病毒感染-Python-OD統一考試(C卷)

題目描述: 一個局域網內有很多臺電腦,分別標注為0 - N-1的數字。相連接的電腦距離不一樣,所以感染時間不一樣,感染時間用t表示。 其中網絡內一個電腦被病毒感染,其感染網絡內所有的電腦需要最少需要多長時間。如果最后有電腦不會感染,則返回-1 給定一個數組times表示一個…

在Spring Boot中如何實現異常處理?

在Spring Boot中&#xff0c;異常處理可以通過幾種方式實現&#xff0c;以提高應用程序的健壯性和用戶體驗。這些方法包括使用ControllerAdvice注解、ExceptionHandler注解、實現ErrorController接口等。下面是一些實現Spring Boot異常處理的常用方法&#xff1a; 1. 使用Cont…

Git實戰(2)

git work flow ------------------------------------------------------- ---------------------------------------------------------------- 場景問題及處理 問題1&#xff1a;最近提交了 a,b,c,d記錄&#xff0c;想把b記錄刪掉其他提交記錄保留&#xff1a; git reset …

【C++ 編程指南】

C 編程指南 ■ C環境安裝■ C 基本語法■ 預定義宏■ # 和 ## 運算符■ C 引用■ C 命名空間■ 定義命名空間■ using 指令■ 嵌套的命名空間 ■ String類■ 類■ 類的static靜態成員 ■ C 繼承■ 繼承類型 public、protected 或 private■ 訪問控制和繼承■ 多繼承■ 數據抽象…

機器學習-面經

經歷了2023年的秋招&#xff0c;現在也已經入職半年了&#xff0c;空閑時間將面試中可能遇到的機器學習問題整理了一下&#xff0c;可能答案也會有錯誤的&#xff0c;希望大家能指出&#xff01;另外&#xff0c;不論是實習&#xff0c;還是校招&#xff0c;都祝福大家能夠拿到…

990-28產品經理:Different types of IT risk 不同類型的IT風險

Your IT systems and the information that you hold on them face a wide range of risks. If your business relies on technology for key operations and activities, you need to be aware of the range and nature of those threats. 您的IT系統和您在其中持有的信息面臨…

數據結構c版(2)——二叉樹

本章我們來了解一下二叉樹這一概念。 目錄 1.樹概念及結構 1.1樹的概念??????? 1.2 樹的特點&#xff1a; 1.3 樹的相關概念 1.4 樹的表示??????? 1.5 樹在實際中的運用&#xff08;表示文件系統的目錄樹結構&#xff09; 2.二叉樹概念及結構 2.1概念 …

Qt 簡約美觀的動畫 擺鐘風格 第十季

&#x1f60a; 今天給大家分享一個擺鐘風格的加載動畫 &#x1f60a; 效果如下: 最近工作忙起來了 , 后續再分享其他有趣的加載動畫吧. 一共三個文件 , 可以直接編譯運行 //main.cpp #include "LoadingAnimWidget.h" #include <QApplication> #include <Q…

【C++】用文件流的put和get成員函數讀寫文件

題目 編寫一個mycopy程序&#xff0c;實現文件復制的功能。用法是在控制臺輸入&#xff1a; mycooy 源文件名 目標文件名 參數介紹 m a i n main main 函數的參數有兩個&#xff0c;一個int類型參數和一個指針數組。 a r g c argc argc 表示參數的個數。參數為void時 a r g …

機器人 標準DH與改進DH

文章目錄 1 建立機器人坐標系1.1 連桿編號1.2 關節編號1.3 坐標系方向2 標準DH(STD)2.1 確定X軸方向2.2 建模步驟2.3 變換順序2.4 變換矩陣3 改進DH(MDH)3.1 確定X軸方向3.2 建模步驟3.3 變換順序3.4 變換矩陣4 標準DH與改進DH區別5 Matlab示例參考鏈接1 建立機器人坐標系 1.1…

Elasticsearch:如何創建搜索引擎

作者&#xff1a;Jessica Taylor 搜索引擎是生活中我們認為理所當然的事情之一。 每當我們尋找某些東西時&#xff0c;我們都會將一個單詞或短語放入搜索引擎&#xff0c;就像魔術一樣&#xff0c;它會為我們提供一個匹配結果列表。 現在可能感覺不那么神奇了&#xff0c;因為這…

Go-知識struct

Go-知識struct 1. struct 的定義1.1 定義字段1.2 定義方法 2. struct的復用3. 方法受體4. 字段標簽4.1 Tag是Struct的一部分4.2 Tag 的約定4.3 Tag 的獲取 githupio地址&#xff1a;https://a18792721831.github.io/ 1. struct 的定義 Go 語言的struct與Java中的class類似&am…