我正在做最後幾天的練習,有這個警告(如標題所示)。我嘗試了一堆東西,但我不知道如何完全解決這個問題。我不擅長編程,所以有錯誤。下面是我使用的結構(這不能被改變,因爲這是他們是如何給出):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