C語言 編寫strcpy函式

2021-07-13 08:49:36 字數 493 閱讀 6678

很多公司的面試官在面試程式設計師的時候

,要求應聘者寫出庫函式strcpy()

的工作方

式或者叫實現,很多人以為這個題目很簡單,實則不然,別看這麼乙個小小的函式

,它可以從三個方面來考查:

(1)程式設計風格

(2)出錯處理

(3)演算法複雜度分析(用於提高效能)

最好的寫法如下:

**如下:

#include #include #include //鏈式訪問

char * my_strcpy(char *dest, const char *src)

int main()

同樣寫出strlen函式

int strlen( const char *str ) //輸入引數const

return len;

}

本文出自 「scen」 部落格,請務必保留此出處

用C 編寫strcpy函式

已知strcpy函式的原型是 char strcpy char strdest,const char strsrc 1.不呼叫庫函式,實現strcpy函式。2.解釋為什麼要返回char 解說 1.strcpy的實現 char strcpy char strdest,const char strsrc...

編寫strcpy 函式

已知 strcpy 函式的原型是 char strcpy char strdest,const char strsrc 其中 strdest 是目的字串,strsrc 是源字串。1 不呼叫c c 的字串庫函式,請編寫函式 strcpy char strcpy char strdest,const c...

編寫strcpy函式

char strcpy char strdest,const char strsrc 2 strcpy能把strsrc的內容複製到strdest,為什麼還要char 型別的返回值?答 為了實現鏈式表示式。2分 例如 int length strlen strcpy strdest,hello wor...