모든 도움을 주신 분들께 감사드립니다. 마지막 문제가 하나 있습니다. 웹 사이트 소스를 char var에 넣은 다음 제품 제목을 읽습니다. 그걸 얻었습니다.) 그러나 neweggs 페이지의 추천 제품 중 하나에서 소스 또는 HTML 만 참여하면 작동합니다. 저는이 프로그램이 충돌하고 있다고 생각합니다. 왜냐하면 3 개의 타이틀을 모두 가져 와서 배열에 넣어야 할 때 어떤 제목을 골라야할지 모르기 때문입니다. 어떤 아이디어? 감사. 여기 파서 코드 :C++, 웹 사이트에서 텍스트 가져 오기, 일부 3
상관 용액을 크게 받고있다.
/**
* num_to_next -
* takes in a pointer to a string and then counts how many
* characters are until the next occurance of the specified character
* @ptr: the pointer to a string in which to search
* @c: char delimiter to search until
**/
int num_to_next(char *ptr, char c)
{
unsigned int i = 0;
for (i = 0; i < strlen(ptr); i++) {
if (ptr[i] == c) {
return i;
}
}
return -1;
}
/**
* space_to_underscore -
* this should help to alleviate some problems when dealing with
* filepaths that have spaces in them (basically just changes all
* spaces in a string to underscores)
* @string: the string to convert, yo
**/
int space_to_underscore(char *string)
{
for (unsigned int i = 0; i < strlen(string); i++) {
if (string[i] == ' ') {
string[i] = '_';
}
}
return 0;
}
char *file_name = (char *)malloc(sizeof(char *)); // allocate memory for where the app name will be stored
memset(file_name, 0, sizeof(file_name)); // zero the memory
char td_one[] = "<ul class="featureCells"><li id="ItemCell" class="cell">";
char *pstr = strstr(buffer, td_one) + strlen(td_one) + 6; // buffer is the source
char *poop = pstr + num_to_next(pstr, '>') + 1;
int blah = num_to_next(poop, '<');
strncpy(file_name, poop, blah);
// null terminate the string //
file_name[blah] = '\0';
space_to_underscore(file_name);
MessageBox(NULL, file_name, "Product Name", MB_OK);
free(file_name);