Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Não consigo inserir nome no nó da árvore, alguém pode me dizer onde estou a errar e como superar?

+1 vote
asked Nov 9, 2019 by MFlor
struct item2

{

char nome[];

};

typedef struct item2 Item2;

Item item2create(char nomes[])

{

Item2 item2;

item2.nome = nomes;

return item2;

1 Answer

0 votes
answered Aug 6, 2025 by Jerry Jeremiah (2,040 points)

You can't create "struct item2 char nome[]; };" because there is no size on the array.  And you can't assign an array to an array like "item2.nome = nomes;" - you need to use something like strcpy().  So it would look like this: https://onlinegdb.com/JCd6_IV7X
 

#include <stdio.h>
#include <string.h>

struct item2
{
    char nome[100];
};

typedef struct item2 Item2;

Item2 item2create(char nomes[])
{
    Item2 item2;
    strcpy(item2.nome,nomes);
    return item2;
}

int main()
{
    Item2 item = item2create("Hello World!");
    printf("%s\n",item.nome);
    return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...