Приведенная ниже функция должна заменять символы, найденные в s
, пробелами, если они найдены в toBlank
:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* function blank replaces all characters in the parameter string s
* that are present in the parameter string toBlank with space characters.
* for example, if s were the string "abcdef" and toBlank the string
* "bde", then after calling this function, s would be "a c f" */
void blank(char *s, const char *toBlank){
int i=0, j=0;
while (s[i] != '\0'){
if (s[i] == toBlank[j]){
s[i] = ' ';
}else{
j++;
}
i++;
}
printf("%s", s);
}
int main(void){
blank("abcdef", "bde");
}
Проблема в том, что s
никогда не изменяется.Может кто-нибудь объяснить, что происходит?