初始化問題啊
為什么這樣初始化不行呢
?1 #include <stdio.h>
? 2
? 3 typedef struct {
? 4 ? int price;
? 5 ? char name[10];
? 6 ? int atk;
? 7 } weapon_t;
? 8
? 9 int main(){
?10 ? weapon_t a;
?11 ? a.name="we";
?12 ? a.price=33;
?13 ? a.atk=99;
?14 ? return 0;
?15 }
為什么這樣初始化不行呢
?1 #include <stdio.h>
? 2
? 3 typedef struct {
? 4 ? int price;
? 5 ? char name[10];
? 6 ? int atk;
? 7 } weapon_t;
? 8
? 9 int main(){
?10 ? weapon_t a;
?11 ? a.name="we";
?12 ? a.price=33;
?13 ? a.atk=99;
?14 ? return 0;
?15 }
2016-08-09
舉報
2016-08-10
#include?<stdio.h> typedef?struct?weapon{ ????//?這個地方這么定義 ????char?*name; ????int?atk; ????int?price; }weapon_t; int?main() { ????weapon_t?weapon1; ???? ????weapon1.name="tom"; ????weapon1.atk?=?100; ????weapon1.price?=?200; ????printf("%s?%d?%d\n",weapon1.name,weapon1.atk,weapon1.price); ???? ????return?0; }