Posted on 2014-07-19 12:29
xLsDg 阅读(149)
评论(0) 编辑 收藏 引用 所属分类:
代码库
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int strlen( const char *str )
5 {
6 const char *s = str;
7
8 while ( *++s );
9
10 return ( s - str );
11 }
12
13 char* strcpy( char *to, const char *from )
14 {
15 char *str = to;
16
17 while ( *str++ = *from++ );
18
19 return to;
20 }
21
22 int main()
23 {
24 char str1[] = "Hello World!", str2[15] = "";
25
26 printf( "str1=%s, str1len=%d\n", str1, strlen( str1 ) );
27
28 strcpy( str2, str1 );
29 printf( "str2=%s, str2len=%d\n", str2, strlen( str2 ) );
30
31 return 0;
32 }
33