字符数组与字符串:将下标为0和偶数的字符删除
将s所指字符串中下标为偶数的字符(含下标是0的字符)删除,串中剩余字符形成的新串放在t所指数组中。 例如,当s所指字符串中的内容为:"ABCDEFGHIJK",在t所指数组中的内容应是:"BDFHJ"。。
函数接口定义:
void fun(char *s, char t[ ]) ;
裁判测试程序样例:
在这里给出函数被调用进行测试的例子。例如:
#include <stdio.h>
void fun (char * s, char t[ ]) ;
#include <string.h>
int main()
{
char s[100], t[100];
scanf("%s", s);
fun(s, t);
printf("The result is: %s", t) ;
return 0 ;
}
/* 请在这里填写答案 */
输入样例:
ABCDEFGHIJK
输出样例:
BDFHJ
void fun (char * s, char t[ ])
{
int i = 0;
int j = 0;
while (*s)
{
if (j & 1)//奇数
{
t[i++] = *s;
}
s++;
j++;
}
}