0
How do I make the execution of mine loop generates a registration code automatically?
Error on line 36 - 'book[i]. Cod = i;' [Error] subscripted value is neither array nor Pointer nor vector
Objective since code: register 5 books with information of the same and generate a code automatically for each generated book.
Current code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*Definindo tamanho*/
#define TAM 5
int main(void) {
/*--Criando a struct--*/
struct ficha_do_livro {
int cod;
char nome_da_obra[50];
char nome_do_autor[50];
char nome_da_editora[50];
}livro;
/*--Cadastro do Livro--*/
int i;
for (i = 0; i < TAM; i++) {
printf("\n---------- Cadastro dos Livros -----------\n\n\n");
livro[i].cod = i;
printf("Insira o nome da Obra: ");
fflush(stdin);
fgets(livro.nome_da_obra, 40, stdin);
printf("Insira o nome do autor: ");
fflush(stdin);
fgets(livro.nome_do_autor, 40, stdin);
printf("Insira o nome da Editora: ");
fflush(stdin);
fgets(livro.nome_da_editora, 40, stdin);
}
}
This is just the beginning of a project not the same complete, yet I will put more things so it is still in alpha. vlw by the attention
– user150382
And what does that mean?
– Maniero
You wrote a very vague question, "And what does that mean?" does not specify the context of its comment referring to mine, specifically meant that it is not an objective project, focusing on scope and efficiency of it being its current structure focused on a test and learning development, the structuring of the comment in it is for the near future to have easy understanding of the scope of the algorithm itself.
– user150382
Your comment is very vague, I gave an answer, you commented something that doesn’t seem to have any meaning. The context of my comment is your context-free comment. I haven’t said anything about the context of your project or what you want to do with it. I told you what mistake you made that has a lot of unnecessary things in it, and now that you give some context I can say that unnecessary things are bad for learning.
– Maniero
When you use what you don’t need, you learn wrong, and I hate when people learn wrong, so I always help in everything I can, not just by fixing the error presented, because it doesn’t teach. I usually say "working is different than being right". If you look here you’ll find this and an illustration of what most people’s software is like when they don’t care about doing it right. I noticed that you had the problem solved, but did not understand the solution, so I put in the reply description of the error and what I fixed, but it seems that you did not value it.
– Maniero
Not everyone knows how to structure all kinds of codes, if I’m here it’s because I’m about to clear my doubts and learn from them, I appreciate you helping, but understand that not every form of learning is given in the explanation of mistakes but also when we make them and correct them to learn from them. Learning not only gives a good semantic structure of the code the 'efficient' tornado, but also to err and recognize that you will never know enough about such a subject.
– user150382
It’s your right to believe in this fallacy.
– Maniero