关于开辟动态存储空间强制类型转化问题
我写的代码在注释行有一个warning,我不知道应该强制转换成什么类型,求讲解强制转化的类型与谁对应#include <stdio.h>
#include <stdlib.h>
typedef struct{
char name[10];
int page;
char author[10];
int price;
}BOOK;
int main()
{
int num,i;
printf("Enter book's num:");
scanf("%d",&num);
BOOK* p=(char*)malloc(sizeof(char)*num); //这里有一个 [Warning] initialization from incompatible pointer type
BOOK* q=p;
for(i=0;i<num;i++,p++){
printf("Enter book's name:");
scanf("%s",&p->name);
printf("\nEnter book's page:");
scanf("%d",&p->page);
printf("\nEnter book's author:");
scanf("%s",&p->author);
printf("\nEnter book's price:");
scanf("%d",&p->price);
printf("\n");
}
p=q;
for(i=0;i<num;i++,p++){
printf("book's name : %s",p->name);
printf("\nbook's page : %d",p->page);
printf("\nbook's author : %s",p->author);
printf("\nbook's price : %d",p->price);
}
free(q);
return 0;
}