1
I’m developing a program that has to run a school canteen and on the menu I have an option to search student by number and another to search all students who have a first name in common. Here’s my code, where I can’t see my problem:
void FindStudentsByName(FILE *f) {
//FILE *file;
//const char *filename = "database-aluno.txt";
//file = fopen(filename,"r");
struct Aluno student;
char name[50];
printf("Insira Nome (Primeiro nome) ");
scanf("%s", name);
while (!(feof(f)))
{
fscanf(f, "%s %s %s %lf %d-%d\n", &student.num, student.name,
student.fname,&student.saldo, &student.dia, &student.mes);
if (name == student.name)
{
fprintf(f,"Numero: %d \n", student.num);
fprintf(f,"Nome: %s\n ", student.fname);
}
}
}
I’m pretty sure the mistake is small, but I couldn’t fix it. The output I want is if for example there are 20 students with the name Vitor the program shows me the numbers of the 20 students and their names.
your
database-aluno.txt
has that format?– Guilherme Nascimento
As well as file format ??
– Vitor Ferreira
It is an example of content, you use line break or a format type files csv?
– Guilherme Nascimento
Line Break, actually 1 student corresponds to a Line
– Vitor Ferreira
Another thing, you have to put the structure of
struct Aluno student;
why it is not possible to understand how the code works. Friend please read this link: http://answall.com/help/mcve– Guilherme Nascimento
Actually at the beginning of the program I have a structure called student with the variables indicated in fscanf
– Vitor Ferreira
Even calling the structure for example Student[acstruct]. name where acstruct, type int is a "variable to track the string", the program does not give me the intended output
– Vitor Ferreira
Follow the instructions of the link that I gave you please, so you will get more answers probably, it is difficult to get answers when people have to deduce how works a code that only has a piece. I hope you understand. See you
– Guilherme Nascimento