一道c语言方面的问题,请各位高手帮忙解答一下

来源:百度知道 编辑:UC知道 时间:2024/05/13 15:11:42
请各位高手帮忙解答一下有一个:
字符数组str,数组中存放一个字符串,编程将字符数组中ASCII值为奇数的字符从数组中删除掉,删除后形成的新字符串仍然存放在原来的字符数组str中。

勉强着用吧,调试已经通过.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define max 100

void main()
{
char str[max]={0};
char strcp[max]={0};
int n=0;
int m;
printf("input string:");
scanf("%s",str);
for(int i=0;str[i]!='\0';i++)
{
m=(int)str[i];
if((m%2)==0)
{
strcp[n]=str[i];
n++;
}
}
printf("%s\n",strcp);
strcpy(str,strcp);
printf("%s\n",str);
}

题目的本意应该是只在一个数组里操作
我认为应该是这样做的(已经证实没有错误)
#include <stdio.h>
#include <string.h>
#define max 100
main(){
char str[max];
int i,k;
printf("input string:");
scanf("%s",str);
for(i=0;str[i]!='\0';i++){
if(str[i]%2==0){
k=i;
while(str[k]!='\0'){