Ciao, penso sia meglio usare fgets() & strtok() (devi includere "string.h)
codice:
int main()
{
struct gara user;
char buffer[512] = "";
char *pt = 0;
const int StringSize = 15; /* Lunghezza delle stringhe */
FILE *fp = fopen ("risultati.txt", "r");
if (fp == NULL)
{
printf("Impossibile aprire file \"risultati.txt\"");
getchar();
exit(EXIT_FAILURE);
}
user.nome = malloc (StringSize * sizeof(char));
user.cognome = malloc (StringSize * sizeof(char));
while ( (fgets( buffer, 512, fp ) ) != NULL )
{
pt = strtok( buffer, ";" );
strncpy( user.nome, pt, StringSize-1);
/* strncpy : no null-character is implicitly appended at
the end of destination if source is longer than num. */
user.nome[StringSize-1] = 0;
pt = strtok( NULL, ";" );
strncpy( user.cognome, pt, StringSize-1);
/* strncpy : no null-character ... */
user.cognome[StringSize-1] = 0;
printf("Nome = \"%s\" \tCognome = \"%s\"\n", user.nome, user.cognome);
getchar();
}
return (EXIT_SUCCESS);
}