所以我正在尝试在 K&R 中进行练习。它想让我做一个类似于挤压的功能,我不明白它有什么问题。我已经在办公桌上检查过了。我不想在网上找到解决方案,我想了解为什么我的代码不起作用。
//removes characters that are present in both strings
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAXLTR 15
void removesame(char s1[],char s2[]);
int main(void)
{
char string1[MAXLTR],string2[MAXLTR];
printf("Enter a string: ");
scanf("\n%s",&string1);
printf("\nEnter the letters/words to be removed: ");
scanf("\n%s",&string2);
removesame(string1,string2);
printf("\nFinal output: %s",string1);
getch();
}
void removesame(char s1[],char s2[])
{
char temp[MAXLTR];
int arraycntr,comparecntr;
for(comparecntr = 0; comparecntr < MAXLTR; comparecntr++)
{
for(arraycntr = 0;arraycntr < MAXLTR;arraycntr++)
{
if(s1[arraycntr] == s2[arraycntr])
s1[arraycntr] == '\t';
}
}
comparecntr = 0;
for(arraycntr = 0; arraycntr < MAXLTR; arraycntr++)
{
if(s1[arraycntr] != '\t')
{
temp[comparecntr] = s1[arraycntr];
++comparecntr;
}
}
for(arraycntr = 0; arraycntr < MAXLTR; arraycntr++)
s1[arraycntr] = '\0';
for(arraycntr = 0;arraycntr < MAXLTR; arraycntr++)
s1[arraycntr] = temp[arraycntr];
}