小编pet*_*n80的帖子

C struct问题

我试图在C中学习结构,但我不明白为什么我不能像我的例子那样分配标题:

#include <stdio.h>

struct book_information {
 char title[100];
 int year;
 int page_count;
}my_library;


main()
{

 my_library.title = "Book Title"; // Problem is here, but why?
 my_library.year = 2005;
 my_library.page_count = 944;

 printf("\nTitle: %s\nYear: %d\nPage count: %d\n", my_library.title, my_library.year, my_library.page_count);
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误信息:

books.c: In function ‘main’:
books.c:13: error: incompatible types when assigning to type ‘char[100]’ from type ‘char *’
Run Code Online (Sandbox Code Playgroud)

c struct

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×1

struct ×1