【发布时间】:2014-01-09 09:49:03
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
struct BOOK{
char name[15];
char author[33];
int year[33];
};
struct BOOK *books;
int main(){
int i,noBooks;
noBooks=2;
books=malloc(sizeof(struct BOOK)*noBooks);
books[0].year=1986;
books[0].author="JackLondon";
books[0].name='MartinEden';
getch();
return 0;
}
我的代码就是这样。当我使用scanf时,它可以工作,但我不能这样直接指定。
错误是:
error: incompatible types when assigning to type 'int[33]' from type 'int'|
error: incompatible types when assigning to type 'char[33]' from type 'char *'|
error: incompatible types when assigning to type 'char[15]' from type 'int'|
Build finished: 3 errors, 1 warnings
我怎么能直接任命,我错在哪里?
【问题讨论】:
-
33 个整数的数组存储一年?面向未来的设计;)
-
如果我使用 char *name[15]; 有什么区别?字符 *作者[33];而不是字符名称[15];字符作者[33];
-
请格式化您提交的代码。
标签: c types structure variable-assignment