C语言程序设计第二版(苏小红,王宇颖编)第10章第5题……求大神帮帮忙


设删除字符为c

第一种方法,使用字符数组
#include "stdio.h"

#include "conio.h"

main()
{
char inputStr[1000];
int i, j;
scanf("%s", inputStr);
for(i=0; i<999; i++)
{
if(inputStr[i]=='c')
{
for(j=i; j<998; j++)
{
inputStr[j] = inputStr[j+1];
}
}
}
printf("%s\n", inputStr);
getch();
}

第二种方法,使用字符指针

#include "stdio.h"散纳
#include "灶掘握conio.h"隐庆

main()
{
char* inputStr;
char* chPosi;
scanf("%s", inputStr);
chPosi = strstr(inputStr, "c");
while(chPosi!=NULL)
{
while(*chPosi!=NULL)
{
*chPosi = *(chPosi+1);
chPosi++;
}
chPosi = strstr(inputStr, "c");
}
printf("%s\n", inputStr);
getch();
}