Hi all, i have problem with linked list.
This is the code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
struct Utenti{
char nome [20];
char cognome [20];
char username [20];
char email [20];
};
struct Profilo{
char username [20];
char email [20];
char titolo_video [20];
int durata_video;
int dimensione_video;
};
struct L_utenti{
char nome;
char cognome;
char nick;
char email;
struct nodo *next;
};
struct L_utenti *testa = NULL;
struct L_utenti *nodo;
struct Profilo profilo [N];
struct Utenti utenti [N];
void Lista_utenti(FILE *ptr_archivio);
int main (){
FILE *ptr_archivio;
ptr_archivio = fopen("Archivio.txt" , "r");
Lista_utenti(ptr_archivio);
return 0;
}
void Lista_utenti(FILE *ptr_archivio){
char archivio_array [N];
int i=0;
if (ptr_archivio == NULL){
printf("Errore, file non trovato!");
}
else {
while(fgets(archivio_array, N, ptr_archivio)!= NULL){
sscanf(archivio_array, "%s %s %s %s", utenti[i].nome, utenti[i].cognome, utenti[i].username, utenti[i].email);
printf("Nome: %s\n" , utenti[i].nome);
printf("Cognome: %s\n" , utenti[i].cognome);
printf("Username: %s\n" , utenti[i].username);
printf("Email: %s\n" , utenti[i].email);
printf("\n\n");
i++;
}
fclose(ptr_archivio);
}
for (i=0;i<3;i++){
nodo = malloc(sizeof(struct L_utenti));
nodo->nome = utenti[i].nome;
nodo->cognome = utenti[i].cognome;
nodo->nick = utenti[i].username;
nodo->email = utenti[i].email;
nodo->next=
testa;
testa=nodo;
}
while(testa!=NULL){
printf("%s-->",testa->nome);
printf("%s-->", testa->cognome);
printf("%s-->", testa->nick);
printf("%s-->", testa->email);
testa=testa->next;
}
printf("NULL\n");
}
I have to create a linked list with the name,surname and username members, but the problem is that in the while condition the program crash.
Another question there is a method to read the file and put it into a linked list? whitout using a structure and then passing data in a linked list.
Sorry if my code isn't good but i'm a beginner