mystrcat

#include<stdio.h>
//如果一個數組做為函數的形參傳遞,那么數組可以在被調用的函數中修改
//有時候不希望這個事發生,所以對形參采用const參數
//size_t strlen(const char *s);
//strcpy(char* s1,const char* s2); 
void mystrcat(char *s1,const char *s2)
{int len = 0;while(s2[len]){len++;}while(*s1){s1++;}int i;for(i = 0; i < len; i++){*s1 = *s2;s1++;s2++;}
}int main()
{char s1[10] = "123";char s2[10] = "456";mystrcat(s1,s2);printf("s1 = %s\n",s1);return 0;
} 

?

轉載于:https://www.cnblogs.com/wanghao-boke/p/11006984.html

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

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

相關文章

關于非阻塞的recv的時候返回的處理

注意recv&#xff08;&#xff09;如果讀到數據為0&#xff0c;那么就表示文件結束了&#xff0c;如果在讀的過程中遇到了中斷那么會返回-1&#xff0c;同時置errno為EINTR。 因此判斷recv的條件&#xff1a; 如果read返回<0 如果0 表示文件結束&…

帶參程序

windows環境 #include<stdio.h>int main(int argc, char *argv[]) {printf("argc %d\n", argc);for (int i 0; i < argc; i){printf("argv[%d] %s\n",i, argv[i]);}system("pause");return 0; } windows環境下&#xff0c;帶參函數…

Ubuntu安裝mysql步驟

1.打開終端&#xff0c;輸入&#xff1a; sudo apt-get updata 輸入root用戶密碼 2.更新完畢后&#xff0c;輸入 sudo apt-get install mysql-server ubuntu14.04安裝中間會讓你設置密碼&#xff0c;輸入密碼后點擊確認(mysql123) 3.安裝結束后&#xff0c;查看端口號是否開啟 …

Pthread創建線程后必須使用join或detach釋放線程資源

這兩天在看Pthread 資料的時候&#xff0c;無意中看到這樣一句話(man pthread_detach): Either pthread_join(3) or pthread_detach() should be called for each thread that an application creates, so that system resources for the thread can be released. …

二維數組求平均值(指針的使用)

#include<stdio.h>int main() {int buf[3][5] {{1,2,3,4,5},{4,5,6,7,8},{7,8,9,10,11}};int i;int j;//求行平均值 for(i 0; i < 3; i){int sum 0;for(j 0; j < 5; j){sum (*(*(buf i) j));}printf("sum %d\n",sum/5);}//求列平均值for(i 0; i …

linux終端關閉時為什么會導致在其上啟動的進程退出?

現象 經常在linux下開發的人應該都有這樣的經驗&#xff0c;就是在終端上啟動的程序&#xff0c;在關閉終端時&#xff0c;這個程序的進程也被一起關閉了。看下面這個程序&#xff0c;為了使進程永遠運行&#xff0c;在輸出helloworld后&#xff0c;循環調用sleep&#xff1a; …

二維數組做函數參數傳遞

#include<stdio.h> //#include<> //二位數組作為函數參數時&#xff0c;可以不指定第一個下標 void print_buf(int (*p)[3],int a,int b) //void print_buf(int p[][3],int a,int b) {int i,j;for(i 0 ; i < a; i){for(j 0; j < b; j){printf("p[%…

libevent源碼深度剖析

第一章 1&#xff0c;前言 Libevent是一個輕量級的開源高性能網絡庫&#xff0c;使用者眾多&#xff0c;研究者更甚&#xff0c;相關文章也不少。寫這一系列文章的用意在于&#xff0c;一則分享心得&#xff1b;二則對libevent代碼和設計思想做系統的、更深層次的分析&#xff…

函數返回指針類型(strchr函數)

#include<stdio.h> #include<string.h> char *mystrchr(char *s,char c) {while(*s){if(*s c){return s;}s;}return NULL; }int main() {char str[100] "hello world";//char* s strchr(str,a);char *s mystrchr(str,e);//返回ello world字符串 prin…

函數與指針

#include<stdio.h>int add(int a,int b) {return ab; }int main() {void *p(int,char *); //聲明了一個函數 &#xff0c;函數名為p&#xff0c;函數返回值為void*,函數的 void (*p)(int,char *);//定義了一個指向參數為int和char*返回值為void的函數指針//定義一個參數為…

使用指針在函數中交換數值

#include<stdio.h>void swap(int* a,int *b) {/*int temp *a;*a * b;*b temp;*/*a *b;*b *a - *b;*a *a - *b; }int main() {int a 10;int b 20;swap(&a,&b);printf("a %d,b %d\n",a,b);} 轉載于:https://www.cnblogs.com/wanghao-boke/p/1…

linux C 基于鏈表鏈的定時器

源碼如下&#xff1a;util_timer.h#ifndef LST_TIMER#define LST_TIMER#include <time.h>#include <sys/time.h>#include <stdlib.h>#include <signal.h>#define BUFFER_SIZE 64struct util_timer;/*struct client_data{sockaddr_in address;int sockf…

libevent學習筆記 一、基礎知識

一、libevent是什么libevent是一個輕量級的開源的高性能的事件觸發的網絡庫&#xff0c;適用于windows、linux、bsd等多種平臺&#xff0c;內部使用select、epoll、kqueue等系統調用管理事件機制。它被眾多的開源項目使用&#xff0c;例如大名鼎鼎的memcached等。特點&#xff…

漢字逆置

在計算機中&#xff0c;一個漢字用無法用1個字節來表示 #include<stdio.h> int main() {char buf[256] "你好";int len 0;while(buf[len]);len--;printf("%d\n",len);// 4一個漢字兩個字節 //printf("%p\n",buf);return 0; } 在windows下…

libevent項目分析(一) -- 準備階段

項目的簡介 我理解libevent是一個輕量級的&#xff0c;跨平臺高效的&#xff08;C語言實現&#xff09;事件驅動庫&#xff0c;類似于ACE項目中的ACE_Reactor&#xff0c;它實現了網絡通訊套接口I/O事件&#xff0c;定時器事件&#xff0c;信號事件的監聽和事件處理函數回調機制…

混合字符串字符數統計

因為漢字占一個以上字節&#xff0c;如何統計一個既有漢字又有字母的字符串呢&#xff1f; 漢字在計算機中的ASCII是以負數來與其他普通字符的ASCII區分的。 #include<stdio.h> int main() {char buf[256] "你好世界";printf("%d\n",buf[0]); //-60…

清除字符串空格

1.清除字符串中右邊的空格 從字符串尾部開始&#xff0c;找到非空格處&#xff0c;將下一個字符置為0即可。 //清除右邊空格 #include<stdio.h> int main() {char buf[] "hello world ";int len 0;//calculate the length of stringwhile(buf[len]);le…

淺談auto_ptr智能指針

引入智能指針&#xff1a;智能指針的實現原理&#xff1a; 資源分配即初始化RAII(Resource Acquisition Is Initialization)&#xff1a; 定義一個類來封裝資源的分配和釋放&#xff0c;在構造函數完成資源的分配和初始化&#xff0c;在析構函數完成資源的清理&#xff0c;可…

隨機數

隨機數產生器rand(),頭文件為#include<stdlib.h> #include<stdio.h> #include<stdlib.h>int main() {int value;int i;for(i 0; i < 10; i){value rand();printf("value %d\n",value);}return 0; } 運行結果&#xff1a; value 41 value 1…

多重繼承之虛繼承(主要是為了解決產生的數據冗余問題)

虛繼承 是面向對象編程中的一種技術&#xff0c;是指一個指定的基類&#xff0c;在繼承體系結構中&#xff0c;將其成員數據實例共享給也從這個基類型直接或間接派生的其它類。形式&#xff1a;在繼承定義中包含了virtual關鍵字的繼承關系&#xff0c;如下圖中&#xff0c;類A就…