微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何启动结构的特定期限

如何解决如何启动结构的特定期限

我正在尝试解决一个练习,但遇到了一些问题。 该练习包括实施更改和附加功能 包含在用于操作结构向量的函数库中。 所以我必须在我的库中实现一个函数

  1. 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 举报,一经查实,本站将立刻删除。