casting - warning: assignment makes integer from pointer without a cast. whats wrong? -
i got warning "warning: assignment makes integer pointer without cast"! want figure out mean? , need change in fucntion create_rectangle..... thank you. appreciated
struct point { int x; int y; }; struct rectangle { struct point upperleft; struct point lowerright; char label[namesize + 1]; };
and code:
struct rectangle *create_rectangle(struct point ul, struct point lr, char *label) { struct rectangle *r = malloc(sizeof(struct rectangle)); r->upperleft=ul; r->lowerright=lr; r->label[namesize+1]= strncpy(r->label,label,namesize); //here warning r->label[namesize] = '\0'; return r; }
strncpy
returns pointer assigning char. (actually, assigning illegal address r->label[namesize+1]
beyond bounds of array.)
it should
struct rectangle *create_rectangle(struct point ul, struct point lr, char *label) { struct rectangle *r = malloc(sizeof(struct rectangle)); r->upperleft=ul; r->lowerright=lr; strncpy(r->label,label,namesize); r->label[namesize] = '\0'; return r; }
Comments
Post a Comment