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