给一串字符 按奇偶数位输出

 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 }

 

转载于:https://www.cnblogs.com/linst/p/4857092.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值