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
|
#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;
}
|
本文转自 七十七快 51CTO博客,原文链接:http://blog.51cto.com/10324228/1686771