简体   繁体   中英

Fill in struct table

typedef struct bat {
  char * ch[30];
  int tp;
}
bat;



int main() {
  bat ba[5];
  ba = {
    {
      "Tropilleur", 2
    }, {
      "sous-marin", 3
    }, {
      "contre torpilleur", 3
    }, {
      "croiseur", 4
    }, {
      "porte avion", 5
    }
  };


  return 1;
}

error: expected expression before '{' token
ba = {{"Tropilleur",2}, ^

Can anyone help with fill in a table of struct please!

You cannot assign an array with an initializer list after declaration. If you combine your declaration with your initializer list, that should clear up your issue.

Additionally, check your struct definition, where you declare a pointer to a char array. You will likely want a pointer or an array, not both in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM