k&r book (The C Programming Language) を使用して C でプログラムを作成する方法を学んでいますが、演習の 1 つに問題があります。文字列 s2 内の任意の文字と一致する文字列 s1 内の文字を検出して削除するように求めています。
したがって、s1 = "A"; とします。
そして s2 = "AABAACAADAAE"
「BCDE」を返してほしい
私はそれに向けて正しい道を進んでいることを知っています。プログラムをうまく設計する方法がわかりません。追加のヒントを教えてください。二分探索木アルゴリズムについて読み込もうとしましたが、このありふれたタスクには少し高度すぎると感じました。
みんな、ありがとう!
/* An alternate version of squeeze(s1, s2) that deletes each character in
* s1 that matches any character in the string s2
*
* Angie@odfx.org
*/
#include <stdio.h>
#include <string.h>
void squeeze(char s[], char t[]);
char string[] = "BAD";
char sstring[] = "ABC";
int
main(void)
{
squeeze(string, sstring);
return 0;
}
void
squeeze(char s[], char t[])
{
int i, j, d;
d = 0;
if(strstr(s, t) == NULL)
printf("%c", s[i]);
s[j] = '\0';
}