#include<stdio.h>
#include "stdlib.h"
#include "string.h"
#define N 1000
int main()
{
FILE *fp;
char em[1000];
char temp[N],*first=NULL,*last=NULL;
int i=0;
char* num;
if((fp=fopen("tt.xml","r"))==NULL)
{
printf("have an error to open file!\n");
exit(1);
}
while(fgets(temp,N-1,fp))
{
if(strstr(temp,"<age>")!=NULL)
{
first=strstr(temp,"<age>");
last=strstr(temp,"</age>");
num=(char*)malloc(sizeof(char)*(last-first-4));
memcpy(num,first+5,last-first-5);
num[last-first-5]='\0';
printf("from[%d]:%s\n",i,num);
}
else
printf("ss\n");
}
}
不知道为什么读不出xml里面的信息,而且输出了13行ss,我的文本就只有12行
#include "stdlib.h"
#include "string.h"
#define N 1000
int main()
{
FILE *fp;
char em[1000];
char temp[N],*first=NULL,*last=NULL;
int i=0;
char* num;
if((fp=fopen("tt.xml","r"))==NULL)
{
printf("have an error to open file!\n");
exit(1);
}
while(fgets(temp,N-1,fp))
{
if(strstr(temp,"<age>")!=NULL)
{
first=strstr(temp,"<age>");
last=strstr(temp,"</age>");
num=(char*)malloc(sizeof(char)*(last-first-4));
memcpy(num,first+5,last-first-5);
num[last-first-5]='\0';
printf("from[%d]:%s\n",i,num);
}
else
printf("ss\n");
}
}
不知道为什么读不出xml里面的信息,而且输出了13行ss,我的文本就只有12行
-
这个看看,感谢
嘿








白毛天下第一
unreal
光影

