这个是我的程序的简化例子,能够编译通过,在运行的时候,却出现了错误,请教大家,哪里有问题呢?
#include "stdlib.h"
#include "stddef.h"
#include "string.h"
#include "ctype.h"
#include "stdio.h"
#include "math.h"
#include "assert.h"
struct feanode
{
char feaname[10];
char *c_range[5];
}feanode;
struct feanode nb1={"adcde",{"aaa","bbb","ccc","ddd","eee"}};
void memcopy(struct feanode *dest, struct feanode *sour)
{
int j;
struct feanode *p,*q;
char **ch1,**ch2;
p=sour;
q=dest;
memcpy(q,p,sizeof(struct feanode));
ch1=p->c_range;
ch2=q->c_range;
for(j=0; j<3; j++)
strcpy(*(ch2+j),*(ch1+j));
}
void main()
{
int j;
struct feanode *nb2;
nb2=(struct feanode *)malloc(sizeof(struct feanode));
assert(nb2!=NULL);
memcopy(nb2,&nb1);
for(j=0; j<5; j++)
strcpy(*(nb1.c_range+j),*(nb2->c_range+j));
for(j=0; j<5; j++)
printf("%s\n",*(nb2->c_range+j));
}
多谢了!