结构体指针,操纵成员结构体变量的成员出现问题,具体请见下代码
#include<stdio.h>#include<string.h>#include<malloc.h>#defineMAX40000structdata{charID...
#include <stdio.h>#include <string.h>
#include <malloc.h>
#define MAX 40000
struct data {char ID[10];
char name1[10];
char name2[10];
char date[5];
};
struct name {char na[MAX][9];
int length;
};
struct alldate {char da[12][5];
int length;
};//基本数据类型
struct stk {data s;
name n;
alldate d;
};//操作数据
struct data *p = (struct data*)malloc(sizeof(struct data));struct stk *q = (struct stk*)malloc(sizeof(struct stk));
void main(){
q->n.length = 0;
q->d.length = 0;
FILE *fp; fp = fopen("e:\\stk1.txt","r");
if(!fp)
printf("fail to open file!\n");//打开源文件读取数据
FILE *fp1; fp1 = fopen("e:\\stkk.txt","w");
if(!fp1)
printf("fail to open file!\n");//打开结果文件写入数据
FILE *fp2;
while(fscanf(fp , "%s%s%s%s" , p->ID , p->name1 , p->name2 , p->date) != EOF){ fp2 = fp;
strcpy(q->s.ID,p->ID);
strcpy(q->s.name1,p->name1);
strcpy(q->s.name2,p->name2);
strcpy(q->s.date,p->date);
strcpy(q->n.name[q->n.length++],p->name1);
strcpy(q->n.name[q->n.length++],p->name2);
strcpy(q->d.da[q->d.length++],p->date);
while(fscanf(fp2 , "%s%s%s%s" , p->ID , p->name1 , p->name2 , p->date) != EOF){ int i;
if(!strcmp(q->s.name1,p->name1) || !strcmp(q->s.name1,p->name2)
|| !strcmp(q->s.name2,p->name1) || !strcmp(q->s.name1,p->name1))
for(i = 0; i < q->n.length; i++)
if(!strcmp(q->n.name[i] , p->name1))
break;
if(i == q->n.length)
strcpy(q->n.name[q->n.length++],p->name1);
for(i = 0; i < q->n.length; i++) if(!strcmp(q->n.name[i] , p->name2))
break;
if(i == q->n.length)
strcpy(q->n.name[q->n.length++],p->name2);
for(i = 0; i < q->d.length; i++) if(!strcmp(q->d.da[i] , p->date))
break;
if(i == q->d.length)
strcpy(q->d.da[q->n.length++],p->date);
}//while
fwrite(q,sizeof(struct stk),1,fp1);
}
fclose(fp);
fclose(fp1);
fclose(fp2);
free(p);
free(q);
}
编译显示此处出了错误:
C:\Program Files\Microsoft Visual Studio\COMMON\MSDev98\Bin\stk.cpp(56) : error C2274: 'function-style cast' : illegal as right side of '.' operator
请问该如何解决? 展开
#include <malloc.h>
#define MAX 40000
struct data {char ID[10];
char name1[10];
char name2[10];
char date[5];
};
struct name {char na[MAX][9];
int length;
};
struct alldate {char da[12][5];
int length;
};//基本数据类型
struct stk {data s;
name n;
alldate d;
};//操作数据
struct data *p = (struct data*)malloc(sizeof(struct data));struct stk *q = (struct stk*)malloc(sizeof(struct stk));
void main(){
q->n.length = 0;
q->d.length = 0;
FILE *fp; fp = fopen("e:\\stk1.txt","r");
if(!fp)
printf("fail to open file!\n");//打开源文件读取数据
FILE *fp1; fp1 = fopen("e:\\stkk.txt","w");
if(!fp1)
printf("fail to open file!\n");//打开结果文件写入数据
FILE *fp2;
while(fscanf(fp , "%s%s%s%s" , p->ID , p->name1 , p->name2 , p->date) != EOF){ fp2 = fp;
strcpy(q->s.ID,p->ID);
strcpy(q->s.name1,p->name1);
strcpy(q->s.name2,p->name2);
strcpy(q->s.date,p->date);
strcpy(q->n.name[q->n.length++],p->name1);
strcpy(q->n.name[q->n.length++],p->name2);
strcpy(q->d.da[q->d.length++],p->date);
while(fscanf(fp2 , "%s%s%s%s" , p->ID , p->name1 , p->name2 , p->date) != EOF){ int i;
if(!strcmp(q->s.name1,p->name1) || !strcmp(q->s.name1,p->name2)
|| !strcmp(q->s.name2,p->name1) || !strcmp(q->s.name1,p->name1))
for(i = 0; i < q->n.length; i++)
if(!strcmp(q->n.name[i] , p->name1))
break;
if(i == q->n.length)
strcpy(q->n.name[q->n.length++],p->name1);
for(i = 0; i < q->n.length; i++) if(!strcmp(q->n.name[i] , p->name2))
break;
if(i == q->n.length)
strcpy(q->n.name[q->n.length++],p->name2);
for(i = 0; i < q->d.length; i++) if(!strcmp(q->d.da[i] , p->date))
break;
if(i == q->d.length)
strcpy(q->d.da[q->n.length++],p->date);
}//while
fwrite(q,sizeof(struct stk),1,fp1);
}
fclose(fp);
fclose(fp1);
fclose(fp2);
free(p);
free(q);
}
编译显示此处出了错误:
C:\Program Files\Microsoft Visual Studio\COMMON\MSDev98\Bin\stk.cpp(56) : error C2274: 'function-style cast' : illegal as right side of '.' operator
请问该如何解决? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询