How do I create a list with numbers read from a file? I can't seem to understand how to do that, because I don't know how many numbers the sequence contains, so how am I supposed to know how many nodes my list has to be composed of. Here is the code I wrote: does the fgets command create a full list or it just fills the first node?
#include <stdio.h>
#include <stdlib.h>
int Sequenza (fp f1, fp f2, fp f3);
typedef FILE* fp;
typedef struct Nd{
int dato;
struct Nd* next;
} Nodo;
typedef Nodo* lista;
int Sequenza (fp f1, fp f2, fp f3){
lista seq1, seq2;
seq1 = malloc (sizeof(Nodo));
seq2 = malloc (sizeof(Nodo));
f1 = fopen ("sequenza1.txt", "r");
f2 = fopen ("sequenza2.txt", "r");
if (f1 == NULL || f2 == NULL){
printf ("Errore nell'apertura di uno dei due file\n");
return 0;
} else {
while (!feof(f1) && !feof(f2)){
fgets (seq1, MAX, f1);
fgets (seq2, MAX, f2);
}
}
fclose (f1);
fclose (f2);
}
I'm not sure that fgets creates a full list, but just fills in the first node.