标签:line str string har blog argc 字符 hello while
1)字符串函数strlen的实现
#include <stdio.h> #include <string.h> size_t mylen(const char* s) { int cnt = 0; int idx = 0; while (s[idx] != ‘\0‘ ){ idx++; cnt++; } return cnt; } int main(int argc, char const *argv[]) { char line[] = "HELLO"; printf("strlen=%lu\n", mylen(line)); return 0; }
2)strcpy 函数实现
char* mycpy(char* dst, const char* src) { char* ret = dst; while(*src != ‘\0‘){ *dst++ = *src++; } *dst =‘\0‘; return rest; }
标签:line str string har blog argc 字符 hello while
原文地址:http://www.cnblogs.com/apeter/p/6817513.html