char[10] 循环生成"book1","book2","book3"...字符串

我在结构体里定义了一个char name[10]的字符数组,我想通过循环给这个数组分别赋值为
"book1","book2","book3"...不知道使用什么样的办法啊?

  1. 若想让name[10]数组里面存有"book1","book2","book3"...等字符串,那么name应该是一个指针数组。所以应该使用到二级指针,你可一查找一下相关资料。
  2. 若想name[10]里面只存放一本书的名字,那么我下面这种方法可以实现。只是我这里存放各种书名字的数组为结构体数组。 #include #include

typedef struct Book
{
char name[10];
}BOOK;

int main(void)
{
char name[10]; //从键盘获取书名
BOOK type_book[10];//存放10本书书名的数组
int i = 0;
for(i = 0; i < 10; i++)
{
printf("Please input the name of the %dth book:", i+1);
scanf("%s", name);
strcpy(type_book[i].name,name); //将获取的书名拷贝到结构体数组中
}

for(i = 0; i < 10; i++)
{
    printf("The %dth book'name:%s\n", i+1, type_book[i].name);//显示结构体数组中的值
}
printf("\n");

return 0;

}

应该是char*[],因为这是多个字符串,相当于char指针的数组