程序报memory fault错误,请高手指点
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/*
Name:
Copyright:
Author:
Date: 13-08-10 19:33
Description:
*/
void parse_xml (char * line){
/*根据=来解析*/
char row[] = "<row cola=\"\" colb=\"i222222\"/>";
char *p = NULL;
char *q = NULL;
p=strrstr(line," ");
puts(p);
q = ++p;
p= strrstr(line,"/");
*p = '\0';
puts(q);
p = q;
/*
*q => a="1" b="2"
*/
char col_name[128];
char col_value[1024];
int i=0;
while(p!=NULL){
/* extra col name */
p = strstr(p,"=");
if(p==NULL)break;
*p = '\0';
strcpy(col_name,q);
/*skip " */
p += 2;
q = p;
/* extra col value */
p = strstr(p,"\"");
*p++ = '\0';
strcpy(col_value,q);
i++;
printf("for number:%d",i);
printf("col name:%s,",col_name);
printf("col value:%s\n",col_value);
/*skip blank*/
while(*p==' '){
p++;
}
q = p;
}
}
int main(void)
{
int read=0;
FILE * fp;
char * line = NULL;
int len = 200;
fp = fopen("/tmp/a.xml", "r");
if (fp == NULL)
exit(0);
while ((fgets(line, len, fp)) != NULL) {
printf("%s", line);
/*把每一行转成结构体*/
parse_xml(line);
}
fclose(fp);
return 1;
}