1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include "myString.h"
size_t myStrlen(const char * s) { size_t count = 0; if (NULL == s) { printf("Input Param is invalid!\n"); return -1; } while (*s != '\0') { count++; s++; } return count; }
char * myStrcpy(char * dst, const char * src) { char * ptemp = NULL; if (NULL == dst || NULL == src) { printf("Input Param is invalid!\n"); return NULL; } ptemp = dst; while (*src != '\0') { *ptemp = *src; ptemp++; src++; } *ptemp = '\0'; return dst; }
char * myStrcat(char * dst, const char * src) { char * ptemp = NULL; if (NULL == dst || NULL == src) { printf("Input Param is invalid!\n"); return NULL; } ptemp = dst; while (*ptemp != '\0') { ptemp++; } while (*src != '\0') { *ptemp = *src; ptemp++; src++; } *ptemp = '\0'; return dst; }
int myStrcmp(const char * s1, const char * s2) { if(NULL == s1 || NULL == s2) { printf("Input param is invalid!\n"); exit(-1); } while (*s1 == *s2 && *s1 != '\0' && *s2 != '\0') { s1++; s2++; } return *s1 - *s2; }
|