我正在做最后几天的练习,有这个警告(如标题所示)。我尝试了一堆东西,但我不知道如何完全解决这个问题。我不擅长编程,所以有错误。下面是我使用的结构(这不能被改变,因为这是他们是如何给出):C错误:格式'%s'需要类型为'char *'的参数,但参数2的类型为'char(*)[100]'
typedef struct bookR* book;
struct bookR{
char author[MAXSTRING];
enum genres{fiction,scientific,politics};
int id;
char review[MAXLINES][MAXSTRING];
};
typedef struct nodeR* node;
struct nodeR{
book b;
node next;
};
typedef struct listR* list;
struct listR{
node head, tail;
int size;
};
这里是代码的一部分发生问题:
void addBook(book b, list bList){
char author [MAXSTRING];
int id;
char review [MAXSTRING][MAXLINES];
printf ("Give the author,`enter code here` id and review of the new book respectively");
scanf("%s",author);
scanf("%d",&id);
scanf("%s",review);
node k=(node)malloc(sizeof(struct nodeR));
assert(k);
k->next=NULL;
strcpy(k->b->author,author);
k->b->id=id;
strcpy(k->b->review,review[MAXSTRING]);}
这是我得到的警告:
warning: format '%s' expects argument of type 'char *' but argument 2 has type 'char (*)[100]' [-Wformat=]
scanf("%s",review);
warining:passing argument 1 of 'strcpy' from incompatible pointer tupe [-Wincompatible-pointer-types]
strcpy(k->b->review,review[MAXSTRING]);
任何帮助,非常感谢。感谢您的时间,并为长篇文章感到遗憾。
'的scanf( “%s” 时,回顾)' - >'的scanf( “%S”,综述[指数])' – LPs
我认为解决的办法是隐藏在警告本身。 – SKD
'strcpy(k-> b-> review,review [MAXSTRING]);' - >'strcpy(k-> b-> review [index,review [MAXSTRING-1]);' – LPs