#include <stdio.h> #include <assert.h> #include <stdlib.h> #include <string.h> int substr(char dst[], char src[], int start, int len) { assert(src != NULL && dst != NULL); char *pdst = dst; int lensrc = 0; while (start--) { src++; } lensrc = strlen(src); if (lensrc < len) { len = lensrc; } while (len--) { *dst++ = *src++; } *dst = ‘\0‘; return strlen(pdst); } int main() { char s[] = "abcdefg"; char str[20]; int ret = substr(str, s, 4, 5); printf("%s\n", str); printf("%d\n", ret); system("pause"); return 0; }
本文出自 “打印九九乘法表” 博客,请务必保留此出处http://10324228.blog.51cto.com/10314228/1686771
原文地址:http://10324228.blog.51cto.com/10314228/1686771