解析xml

5年以前  |  阅读数:298 次  |  编程语言:C 
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>

int main()
{
    FILE *fd;
    char buff[1024];
    char *str;

    fd = fopen("taskd.xml", "r");
    if(fd == NULL)
    {
        perror("open");
    }

    while (strstr(buff, "</ROOT>") == NULL)
    {
        fgets(buff, 1024, (FILE*)fd);
        usleep(1000);
        if(strstr(buff, "<TASK>") != NULL)
        {
            str = (char *)malloc(20);
            memset(str, 0, 20);
            memcpy(str, buff+7, 6);
            printf("%s\n", str);
            free(str);
        }
    }
    fclose(fd);
    return 0;
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8