help!!!快啊!!!

来源:百度知道 编辑:UC知道 时间:2024/06/29 01:56:03
2.写函数fun(),其功能是:将s所指字符串中除了下标为偶数、同时ASCII值也为偶数的字符外,其余的全部删除,串中剩余字符所形成的一个新串放在t所指的数组中。
例:若s所指字符串中的内容为ABCDEFG123456,最后t所指的数组中的内容为246。请打开给定的程序在pro2.c,补充完整。提示s[i]%2= =0可判ASCII值是否为偶数。

#include "stdio.h"
#include "conio.h"
#include "string.h"
void fun(char *s,char t[])
{

}
main()
{
char s[100],t[100];
printf("\nPlease enter string s: ");
scanf("%s",s);
fun(s,t);
printf("\nThe result is: %s:",t);
getch();
}

运行通过
void fun(char *s,char t[])
{
char *p=s;
int i=0;
while(*p!='\0')
{
if((int)(*p)%2==0)
{
t[i++]=*p;
}
if(*(p+1)=='\0'||*(p+2)=='\0')
break;
p=p+2;
}
t[i]='\0';

}

#include "stdio.h"
#include "conio.h"
#include "string.h"
void fun(char *s,char t[])
{ int i,j;
for(i=0,j=0;s[i];i+=2)
if(s[i]%2==0){t[j]=s[i];j++;}

}
main()
{
char s[100],t[100];
printf("\nPlease enter string s: ");
scanf("%s",s);
fun(s,t);
printf("\nThe result is: %s:",t);
getch();
}

void fun(char *s,char t[])
{
int i=0,j=0

for(;*s!='\0';s++,i++)
{
if(i%2==0&&(*s)%2==0)
{
continue;
}
else
{
t[j]=(*s);
j