问题描述
我正在尝试解决一个练习,但遇到了一些问题。 该练习包括实施更改和附加功能 包含在用于操作结构向量的函数库中。 所以我必须在我的库中实现一个函数:
- planta *planta_nova (const char *ID,const char *nome_cientifico,char **alcunhas,int n_alcunhas,int n_sementes); 创建 struct planta 的一个实例,将每个参数复制到相应的字段。 每个字段都必须提供有效值,alcunhas 除外,它可能是 如果此工厂没有可用的本地名称,则为 NULL。函数应该返回 指向创建的植物实例的指针,如果发生错误,则为 NULL。
typedef struct
{
/** identify the only on the catalogue **/
char ID[10];
/** cientific designation */
char nome_cientifico[200];
/** nickname list of specie **/
char **alcunhas;
/** total number of nicknames of an specie **/
int n_alcunhas;
/** number of seeds in the storaged **/
int n_sementes;
} planta;
在我尝试启动 alcunhas 后,我遇到了分段错误:
planta *planta_nova(const char *ID,int n_alcunhas,int n_sementes)
{
int i;
planta *item=(planta*)malloc(sizeof(planta));
if(item==NULL)
return NULL;
strcpy(item->nome_cientifico,nome_cientifico);
strcpy(item->ID,ID);
item->n_alcunhas=n_alcunhas;
item->n_sementes=n_sementes;
if(n_alcunhas==0){
item->alcunhas=NULL;
}
else{
for( i=0 ;i < n_alcunhas ;i++){
strcpy(item->alcunhas[i],alcunhas[i]);
}
}
return item;
谢谢你的帮助,希望你明白我在寻求帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)