what the code actually does, is storing the whole line into utenti[i].username so let's say in the file we got "Pierluigi,Pierluigi@gmail.com,1983,messicana,30,6.5"
the whole line will be stored into utenti[i].username even though username max lenght is 20, obviously that wasn't the original purpose of the code, what is intended to do is to store each value into the right variables. I already used this kind of fopen and fscanf code in another one and it actually works, it stores the data in the right variables, but here it wont work. i was trying to understand why it doesn't work but i cant figure it out, so i'm asking here for help.
#include <stdio.h>
#include <stdlib.h>
#include "mystruct.h"//where i get my structures
#define MAX_DIM 1000
utente utenti[MAX_DIM];
int main()
{
FILE *utente;
int i = 0;
if ((utente = fopen("./Dati/utenti.csv", "r")) == NULL)
printf("Impossibile aprire il file.\n");
else{
while(!feof(utente)){
fscanf(utente,"%s,%s,%d,%s,%f,%f", utenti[i].username, utenti[i].email, &utenti[i].n_anno, utenti[i].tradizione, &utenti[i].fasciadiprezzo, &utenti[i].media_voti);
printf("utenti : %s\n", utenti[i].username);
i++;
}
}
fclose(utente);
return 0;
}
and here's the struct contained in mystruct.h
typedef struct utente{
char username[20];
char email[30];
int n_anno;//anno di nascita
char tradizione[20];
float fasciadiprezzo;
float media_voti;
struct prenotazione *p_prenotabili;
struct recensione *valutazioni;
}utente;
where "prenotazioni ..." and "recensione ..." are linked list
im programming with vs_code