Hi,
I'm developing a very small project, and while implementing it I got some issue. I already did this kind of exercises a few times, but I don't seem to understand what is wrong (the scanf to get string/char array input. A compiler error related to the type of variable and or number of arguments.)
I'm using code blocks and windows10 at this moment.
This is still a code in progress, and as a newbie I will also appreciate best practice's tips.
Code:
#include <stdio.h>#include <stdlib.h>
#define MAXINPUT 20 //use this value to max loop (apply later)
struct Book // Structure type definition
{
char title [10];
int pages;
}books[10];
int main()
{
int i = 0;
int option;
while (i < 10)
{
printf("Do you want to enter details of BOOK 1 (yes) or 0 (No)? ");
scanf("%d", &option);
if (option == 1)
{
printf("\n Title name: ");
scanf("%s", &books[i].title);
printf("\n Number of pages: ");
scanf("%d \n", &books[i].pages);
}
else if (option == 0)
{
printf("It was not yes \n");
break;
}
else{
printf("Valid input, go back to main menu \n");
break;
}
i++;
}
// save records to file// to be written
//display records created
for (i = 0; i < 2; i++) {
printf("Book title: ");
puts(books[i].title);
printf("Page number: %d", books[i].pages);
printf("\n");
}
//display all saved record//to be written
return 0;
}
warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[10]' [-Wformat=]