【发布时间】:2016-09-14 10:56:34
【问题描述】:
最近几天我正在做一个 c 练习,我收到了这个警告(如标题所示)。我已经尝试了很多东西,但我真的不知道如何完全解决这个问题。我不擅长编程,所以有错误。以下是我正在使用的结构(无法更改,因为它们是这样给出的):
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",review)-->scanf("%s",review[index]) -
我认为解决方案隐藏在警告本身中。
-
strcpy(k->b->review,review[MAXSTRING]);-->strcpy(k->b->review[index,review[MAXSTRING-1]); -
@LPs 你错过了
]。
标签: c struct compiler-warnings c-strings strcpy