急求用C语言编写"将一个字符串中指定字符(如o)左边的字符全部移到最右边,并删除这个字符”急用!!!!

如“I am a boy.And you?”程序运行结果为“u?I am a b y.And y”
我学的是C程序设计(谭浩强第三版),已经学完了指针,明天上机谁编对这道题给谁加分,所以呈请各位C语言高手马上帮忙写出来,感激不尽!

// 给你简单的写了一个
// 其中原字符串与需要去除的字符全部写死了,你可以将其改写为
// 从外部输入字符串的方式
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define MAX_BUF 512

int main()
{
char src[MAX_BUF] = "I am a boy.And you?";
char cfind = 'o';

char * pPos = NULL;
int iLen = 0;
char dst[MAX_BUF];
memset(dst, 0, MAX_BUF);

while (true)
{
pPos = strchr(src, cfind);
if (NULL == pPos)
{
break;
}

iLen = strlen(pPos);

memcpy(dst, pPos + 1, iLen - 1);
memcpy(dst + iLen - 1, src, strlen(src) - iLen);

memset(src, 0, MAX_BUF);
strcpy(src, dst);
memset(dst, 0, MAX_BUF);
}

return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-26
楼上简单的够呛。囧
相似回答