模擬實現strchr

2021-08-14 09:16:46 字數 825 閱讀 6531

今天

模擬實現的是strchr這個庫函式,還是首先上來簡單介紹一下這個函式是用來做什麼的。

先看看c++官網的正規介紹

其實就是strstr是在字串中尋找字串,而strchr是在字串中尋找某乙個字元。所以說這個的難度相對於strstr來說簡單了很多。

#define _crt_secure_no_warnings 1

#include#includechar *my_strchr(const char *msg, char dest)

*msg++;

}return null;

}int main()

還是要記得

const

char *msg

,不能直接將msg賦值給新建立的char型別中,並且dest和msg不能直接說這兩個相等,dest是字元型別,而msg是指標型別,所以判斷兩個相等的時候是*msg == dest

。這個相對於strstr難度還是降低了很多。

程式執行結果為

還是在編寫**的規範性上有很大的欠缺。尤其是對程式中變數的命名以及對函式的命名上還是需要自己的不斷提公升,不斷的讀取他人的優秀**來進行一定的學習。

模擬實現Spring IOC

通過在類上標註 registration 註冊進容器,injection從容器注入物件 容器類 public class springcontainer else bean.setbeanclass c mappropsmap new hashmap 處理注入屬性 field props c.get...

模擬實現strcmp

函式簡介 原型 int strcmp const char s1,const char s2 所在標頭檔案 string.h 功能 比較字串s1和s2。一般形式 strcmp 字串1,字串2 說明 當s1注意不是 1 當s1 s2時,返回值 0 當s1 s2時,返回正數 注意不是1 如下 int m...

模擬實現strncat

模擬實現strncat 在系統庫函式中,存在strncat這個函式,它用於字串的追加,就是在乙個字串後面再追加乙個字串,它的函式原型為 char strncat char strdest,const char strsource,size t count 在其中,strdest為目標字串,strso...