Good evening.
I am developing a project for the Faculty in C, where I have a data structure to work with data common to "Offenders", or those who have committed an infraction.
typedef struct Infractores
{
int ordemdeEntrada;//ordem de entrada da infração ... começa em 1 acaba em N
char *marca;
char *modelo;
char *matricula;
double valorportagem;
int classeVeiculo;
struct Infractores *seguinte;
};
If you have already noticed I am using pointers to *marca , *modelo
... and I have struct Infractores *seguinte;
. This happens because of having to implement lists in the project.
It turns out that I plan to implement a method to read from a file the latest infringers, for example those who committed infringements yesterday. To achieve this I also developed a method:
void ListaInfractoresAnteriores(Infractores *f)
{
const char *filenameinfractors = "C:/Users/Vitor/documents/visual studio 2013/Projects/AED II/Resolucao_Teste/Projecto/VVManager/lastdayinfractors.txt";
FILE *ficheiroInf = fopen(filenameinfractors, "r");
//struct TesteInfractores auxiliar;
struct Infractores *auxiliar;
auxiliar = f;
while (!feof(ficheiroInf))
{
if (fscanf(ficheiroInf, "%d %s %s %lf %d \n", &auxiliar->ordemdeEntrada, *auxiliar->marca, *auxiliar->modelo, &auxiliar->valorportagem, &auxiliar->classeVeiculo) != NULL)
{
printf("Marca %s",*auxiliar->marca);
}
}
}
In this method I try to test that if the entry of my fscanf()
is <>
(different) from NULL
(Null), then it should write the mark, in this case of the car, that committed the infringement. / p>
I can not read the file using this data structure at all. How can I read data from the file taking into account I did not want to use a new data structure ? Do I have to create new variables ?
Note: I want to use the data structure to manipulate files and manipulate lists .