Reputation: 9
I tried compiling this code but its giving me "passing argument 2 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]". Can someone tell me what i need to do.
struct Book
{
char title[MAX_TITLE_LENGTH+1];
char author[MAX_AUTHOR_LENGTH+1];
int year;
};
void menu_delete_book(void)
{
char temp[300];
int x,b;
int no_books;
fgets(temp,MAX_TITLE_LENGTH,stdin);
{
for(x = 0; x< no_books; x++)
{
if (strcmp (book_array[x].title, temp) == 0)
{
for(x=1; x < no_books -1; x++)
{
for(b = x + 1; b < no_books; b++)
{
strcpy(book_array[x].title, book_array[b].title);
strcpy(book_array[x].author, book_array[b].author);
strcpy(book_array[x].year, book_array[b].year);
}
}
}
}
}
no_books++;
Upvotes: 0
Views: 305
Reputation: 6659
It's complaining about this line:
strcpy(book_array[x].year, book_array[b].year);
Book::year is an integer, not a string. Do this instead:
book_array[x].year = book_array[b].year;
The warning is telling you that the integer values you were passing to strcpy
were being implicitly converted to pointers. It's almost always an error to convert int
to pointer
and in your case, the integers definitely don't contain valid pointer values.
Upvotes: 2