在字符串中除开指定的字符
在字符串中去除指定的字符#include stdio.hvoid squeeze(char s[], int c)/* delete all c from s */in
在字符串中去除指定的字符
#include <stdio.h>
void squeeze(char s[], int c);
/* delete all c from s */
int main()
{
char s[50];
int c;
printf("Please enter a string: ");
scanf("%s", s);
getchar();
printf("Enter the c: ");
scanf("%c", &c);
squeeze(s, c);
return 0;
}
void squeeze(char s[], int c)
{
int i, j;
for (i = j = 0; s[i] != '\0'; ++i) {
if (s[i] != c) {
s[j] = s[i];
++j;
}
}
s[j] = '\0';
printf("%s\n", s);
}
在vc++6.0下运行字符串内容不变,把字符c声明和定义中都改成char再跑一遍就可以去除c,求高手解答~我输入的字符都是字母,在squeeze函数中比较时,不都是自动转成ascii码来比较的吗,为什么改变变量c的类型会有影响? string
[解决办法]哦哦 不好意思 没看你下面文字说明的 以为你让改错的。
你把c输入那个改成scanf("%d", &c);
然后输入c的时候 按照ascii码对应的输入就好。或者你那自定义函数那边转换一下