I have a struct Time
that has a char name[30]
vector, the problem starts when I try to copy a value to this string with the function strcpy()
, it follows the code of stuct
:
typedef struct Time{
char name[30];
int pnts;
int vit, emp, der;
int gf, gt;
struct Time *next;
struct Time *prev;
}time;
and here is the function that implements s trcpy()
:
void addTime(campeonato *c, char name[]){
time t;
strcpy(t.name, name);
t.next = NULL;
t.pnts = t.vit = t.emp = t.der = t.gt = t.gf = 0;
if(c->first == NULL){
c->first = &t;
t.prev = NULL;
} else {
time *p = c->first;
while(p->next != NULL){
p = p->next;
}
p->next = &t;
t.prev = p;
}
}
The main()
looks like this:
campeonato c;
createCamp(&c, "Brasileirao");
addTime(&c, "Palmeiras");
time *t = c.first;
printf("%s", t->name);
return 0;
The value of print for t->name
is always garbage.