ココサブ #751(2007/07/13 11:52 GMT) [ C ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char *data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<rss version=\"2.0\"><channel><title>どう書く?org 新着コメン ト</title><link>http://ja.doukaku.org/</link><description>どう書く?orgに最近投 稿されたコード</description><language>ja</language><lastBuildDate>Fri, 13 Jul 20 07 11:17:01 -0000</lastBuildDate><item><title>ココサブ's comment on ウィンドウの 表示" "</title><link>http://ja.doukaku.org/comment/744/</link><descri ption>" "<a href=\"http://ja.doukaku.org/7/\">ウィンドウの表示< ;/a>" "<hr>"; char *head, *tail; char *result; char *data_p; int result_len; data_p = data; while (1) { head = strstr(data_p, "<lastBuildDate>"); if (head == NULL) break; tail = strstr(head, "</lastBuildDate>"); if (tail == NULL) break; /* 答えの長さを求める */ result_len = (tail - head) + strlen("</lastBuildDate>"); result = malloc((result_len + 1) * sizeof(char)); strncpy(result, head, result_len); result[result_len] = '\0'; printf("%s\n", result); free(result); data_p = tail + strlen("</lastBuildDate>"); } return 0; }
Rating0/0=0.00-0+
[ reply ]
ココサブ
#751()
[
C
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]