0
我編輯了我以前的問題。使用wget命令執行
由於我得到了問題和改變了代碼,現在我有一個不同的問題。如果我使用execle命令,它只會使用wget命令下載一個圖像,否則如果wget命令沒有執行,它會在屏幕上打印所有圖像名稱。我不明白什麼時候有一個while循環,那麼爲什麼它只打印一個圖像。
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<limits.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
void main(int argc, char*argv[])
{
int iFlag;
char cline[100];
FILE*fil = fopen("index.html","rt");
if(fil==NULL)
{
printf("Error in opening file");
}
char*tmpLine;
char*tok;
const char check[10] = "<img";
const char check2[10] = "src=";
char images[50];
strcpy(images,argv[1]);
while(fgets(cline,100,fil)!=NULL)
{
if(strstr(cline,check)!=NULL)
{
tmpLine=strstr(cline,check);
if(strstr(cline,check2)!=NULL)
{
tmpLine=strstr(cline,check2);
tok = strtok(tmpLine,"\"");
while(tok!=NULL)
{
tok = strtok(NULL,"\"");
if(tok[0]!='/')
{
strcat(images,"/");
strcat(images,tok);
printf("\nimage: %s\n",images);
iFlag = execle("/usr/bin/wget","wget","-o","logfile",images,NULL);
if(iFlag<0)
perror("EXECLE ERROR");
break;
}
else
break;
}
memset(&images[0], 50, sizeof(images));
strcpy(images,argv[1]);
}
}
}
}
這是一個很好的替代品嗎? char * tmp =「wget -o logfile」; char * temp =(char *)malloc(tmp +(sizeof(images))); strcpy(temp,tmp); strcat(temp,images); system(temp); – talbinzal