C語言字串庫函式的實現

2022-08-05 17:48:16 字數 1941 閱讀 5523

1.strlen(字串的長度)

size_t strlen(const

char*str)

}size_t strlenbyrecursion(

const

char*str)

size_t __cdecl strlen (const char * str)  //函式庫裡面實現的**

2.strcpy(字串拷貝)

char* strcpy1(char* dst, const

char*src)

dst[i] = '\0'

;

return

dst;

}char* strcpy2(char* dst, const

char*src)

char *  strcpy (char * dest,const char* src)   //函式庫中的實現

while (c != '\0'); 

n = s - src; 

(void) check_bounds_high (src + n); 

(void) check_bounds_high (dest + n); 

return dest; 

}

3.strncpy

char* strncpy(char* dst,const

char* src,int

lenth)

*tmp = '\0'

;

return

dst;

}

char * __cdecl strncpy (char * dest,const char * source,size_t count)  

4.strcat(字串連線)

char* strcat(char* dst, const

char*src)

char * __cdecl strcat (char * dst,const char * src)     //庫中的實現方法

5.strncat

char* strncat(char* dst,const

char*src,size_t lenth)

char * __cdecl strncat (char * front,const char * back,size_t count)     //庫中實現的方法

6.strcmp

int strcmp(const

char* str1, const

char*str2)

return *(unsigned char*)str1 - *(unsigend char*)str2;

}

int __cdecl strcmp (const char * src,const char * dst)      //庫中的實現方式

7.strncmp

int strncmp(const

char* str1, const

char*str2,size_t lenth)

return0;

}

int __cdecl strncmp (const char * first,const char * last,size_t count)     //庫裡實現的方式

return( *(unsigned char *)first - *(unsigned char *)last );

}