cでwgetを使ってWebページをダウンロードしたいと思います。私はこのコードを書きましたが、試してみると、プログラムは指定された名前の一部のみで名前が付けられたページをダウンロードし、ファイル名に無効なエンコーディングが見つかりました。
ページ名はこんな感じ
test0L���i}�X�����L�������R�td]�{��+`��U{�@ (invalid encoding)
私のプログラムの重要な部分はこれです。
#define PAGE "http://deckbox.org/games/mtg/cards?p="
char *cat_url(char *s1, char *s2)
{
char *tmp;
tmp = (char*)malloc(sizeof(char*) * (strlen(s1) + strlen(s2)));
strcat(tmp, s1);
strcat(tmp, s2);
return tmp;
}
void get_card_name(char *pg_name)
{
int i;
int fk;
char *args[6], tmp;
for (i = 0; i < 8; i++) {
tmp = itoa(i);
args[0] = "wget";
args[1] = "-q";
args[2] = cat_url(PAGE, &tmp);
args[3] = "-O";
args[4] = cat_url("test", &tmp);
args[5] = NULL;
if (fork()) {
wait(&fk);
} else {
if (execvp(args[0], args) == -1) {
error_rep("ERROR.\n");
}
}
}
}
どうすれば問題を解決できますか? ありがとう