Allocate memory for a struct with a character pointer in C

后端 未结 6 423
礼貌的吻别
礼貌的吻别 2021-02-02 02:22

I was struggling to fix a code today, then I come across something similar to:

typedef struct {
int a; 
int b; 
int c;
int d;
char* word;
} mystruct;

int main(i         


        
6条回答
  •  一向
    一向 (楼主)
    2021-02-02 02:57

    Use word=malloc(128);

    this will allocate 128 bytes to your varible word,

提交回复
热议问题