C字符串问题看看什么原因

来源:百度知道 编辑:UC知道 时间:2024/06/04 20:12:56
任意输入一组字符串和一个字符,然后删除该字符串中刚才输入的那个字符
#include<stdio.h>
#include<conio.h>
main()
{
int i;
char c;
char s[50];
gets(s);
scanf("%c",&c);
for(i=0;s[i]!='\0';i++)
{
if(s[i]==c)
i--;
}
printf("%s\n",s);
}

if语句使用有问题
if(s[i]==c)
i--;
i--不明确,输出时可以不要用字符串输出,可以改为单个数组元素输出,我调试后的程序如下(希望能给楼主帮助):
#include<stdio.h>
#include<conio.h>
main()
{
int i;
char c;
char s[50];
gets(s);
scanf("%c",&c);
for(i=0;s[i]!='\0';i++)
{
if(s[i]==c) ;
else
printf("%c",s[i]);
}

printf("\n");
}