C: format '% s' expects an argument of type 'char *', but argument 2 is of type 'char (*) [100]'

I have been working on exercises for the past few days, and I have this warning (as the name suggests). I tried a bunch of things, but I really don't know how to fix this exactly. I do not know how to program, so there are errors. Below are the structures that I use (which cannot be changed since they are given):

    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;
};

And here is the part of the code where the problem occurs:

 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]);}

And this is the warning I get:

  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]);

Any help is greatly appreciated. Thanks for your time and sorry for the long post.

+4
source share
2
  • β„–1

    scanf, . :

    char review [MAXSTRING][MAXLINES];
    

    :

    scanf("%s",review);
    

    :

    scanf("%s", review[i]);
    

    i - 0 MAXSTRING-1.

  • β„–2

    , :

    strcpy(k->b->review,review[MAXSTRING]);
    

    , review[MAXSTRING-1]. , . :

    strcpy(k->b->review[index], review[MAXSTRING-1]);
    

:

  • . , malloc.
  • , , :

    array[x][y];
    

    x , y . , , , , .

+1

char review [MAXSTRING][MAXLINES];

, C- .

C- review[index], 0 MAXSTRING-1

So

scanf("%s",review)

- , C- , :

scanf("%s",review[index]);

MAXLINES-1, scanf:

fgets(review[index], MAXLINES, stdin);

review struct bookR.

strcpy(k->b->review,review[MAXSTRING]);

strcpy(k->b->review[index],review[MAXSTRING-1]);

, strcpy : , Undefined .

:

test.c:666:45: warning: declaration does not declare anything
     enum genres{fiction,scientific,politics};
                                             ^

, , struct bookR, :

char review [MAXLINES][MAXSTRING];

, , prinf ans scanf/fgets.

printf ("Give the author: ");
fgets(author, MAXSTRING, stdin);
printf ("Enter id: ");
scanf("%d",&id);
printf ("Enter review of the new book respectively: ");
fgets(review[index], MAXSTRING, stdin);
+2

All Articles