1 #define _CRT_SECURE_NO_WARNINGS
2 #include<stdio.h>
3 #include<stdlib.h>
4 #include<string.h>
5
6 int getStr1Str2(char *source, char *buf1, char *buf2)
7 {
8 char *tmpSource = source;
9 char *tmpBuf1 = buf1;
10 char *tmpBuf2 = buf2;
11
12 int len = 1;
13
14 while (*tmpSource!='\0')
15 {
16 if (len % 2)//奇数
17 {
18
19 *tmpBuf1++ = *tmpSource++;
20 len++;
21 }
22 else
23 {
24 *tmpBuf2++ = *tmpSource++;
25 len++;
26 }
27
28 }
29 *tmpBuf1 = '\0';
30 *tmpBuf2 = '\0';
31 }
32 int main()
33 {
34 char *source = "1a2b3d4z";
35 char *buf1 = (char*)malloc(100);
36 char *buf2 = (char*)malloc(100);
37 getStr1Str2(source, buf1, buf2);
38 printf("buf1奇数位:%s\n",buf1);
39 printf("buf2偶数位:%s\n", buf2);
40 system("pause");
41 return 0;
42 }