The error is exactly what is written, as you declared the variable livro
as a array, it becomes a pointer to a sequence of data, already TAM
is a numerical constant.
C is a static typing language, but weak, so it even lets you make comparisons even if it doesn’t make sense, on a pointer and a simple number are two completely different things it’s like you want to know if an apple and a horse are the same thing, You can’t even begin to compare, so most compilers warn that this will produce a meaningless result. The solution is to compare things that make sense, but we don’t even know exactly what would make sense there, what you’re trying to compare, the only sure thing is that a book can be compared to a 5.
Looking at the whole code on another question you might want to compare the id
of the book, something like that:
if (livro.id > TAM) {
But then book would have to have only one book and not one array of books (what alias the variable should call livros
and not livro
.
If you’re really going to work with array, maybe I’m in a loop and I want to do something like this:
if (livro[i].id > TAM) {
I put in the Github for future reference.
But if there’s a noose maybe I’d like to do if (i > TAM) {
.
But it may be that all options are wrong because the concept is wrong and should not even do this.
After editing, you can see that the problem shouldn’t even exist. The code is already running to register the maximum size, nor allows you to register less than the maximum, nor more, so this if
does not make sense, even if create a control, which is the third option I had given up, it will never enter this if
, then just take it off.
I won’t even try to show you another way to do it better because I already know you’d rather do it your way, even though he’s no good.
I don’t understand the logic. You have a loop where the index varies from 0 to the maximum possible to be placed in the array, in the case of TAM-1, so it is obvious that at the end of the loop you have registered as many books, your test is meaningless.
– anonimo
The test is to indicate if the maximum number of books has been registered, how do I set the value of the maximum array of 5 will always be registered the maximum, but how will the user know if it has been registered if he tries to register more books? Initially I thought to compare the direct array with its size, but as Maniero reported in C the typing is static, in a layman’s way not to compare 'home' with 'boat', then I compared one of the elements of the array that will always be 5 items with the constant to inform if you already have as many books registered.
– user150382
Let me try to explain. At the end of the loop the variable i, which is the variable that should be being tested in if (if (i > TAM)), will always be with the TAM value, since at no point in the loop you interrupt the loop, it will always go to the end (the i<TAM condition of the for command). In this way your test is innocuous because you will always have been registered as many books as possible and your variable i will never be greater than TAM, will be equal.
– anonimo
I understood, but how would I show that it is filled? (sorry my ignorance I am not a programmer in C)
– user150382
Dude, you didn’t implement the option to partially fill just can fully fill in!
– anonimo
Now I get it, thanks for the help.
– user150382