运行程序报 Memory fault(coredump)
#include <stdio.h>#include <string.h>
#include <stdlib.h>
struct list
{
char name[10];
char IPADD;
int port;
}
int main()
{
int i=0;
struct list s[256];
FILE *fp;
FILE *fp1;
fp=fopen("../1.cfg","r");
fp1=fopen("../2.xml","w");
if(fp==NULL)
{
printf("Can't open 1.cfg\n");
return 1;
}
if(fp1==NULL)
{
printf("Can't open 1.xml");
return 1;
}
fprintf(fp1,"%s\n","<?xml>");
fprintf(fp1,"%s\n","<retCfg>");
fprintf(fp1,"%s\n","<list>");
while(!feof(fp))
{
fprintf(fp1,"%s\n","<rspcode>");
fscanf(fp,"%s",s[i].name);
fprintf(fp1,"<name>%s</name>\n",s[i].name);
fscanf(fp,"%s",s[i].IPADD);
fscanf(fp,"%d",&s[i].port);
fprintf(fp1,"<value>%s|%d</value>\n",s[i].IPADD,&s[i].port);
fprintf(fp1,"%s\n","<rscpode>");
i++;
}
fprintf(fp1,"%s\n","</list>");
fprintf(fp1,"%s\n","</retChg>");
return 0;
}
1.cfg文件格式如下:
A1010228 156.2.2.2 5050
A1132435 156.2.2.3 5050
。。。。。。。。。