如果他們在toBlank
發現下面的函數應替換s
發現空格字符:Ç - 比較字符串
#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
永遠不會被修改。有人可以解釋發生了什麼嗎?
請介紹更多的細節「不工作」(編輯你的問題),並選擇一個更好的標題你的進步 - 這是關於在一個字符串替換的東西,而不是比較字符串。 – Mat