Merging/appending 2 lists

So i have to create a function that merges 2 single linked list into one and then
saves the result in a file ,and i have no clue how to do it , the 2 list are generate casually and the number of the nodes of a list is also random

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 typedef struct tcliente{
        int id;
        char nome[30];
        char iva[30];
        double fatturato;
        tcliente(){
                   id=0;
                   nome[0]='\0';
                   iva[0]='\0';
                   fatturato=0.0;
                   }
                   
        tcliente(int i,char n[30],char iv[30],double fatt)
        {id=i;strcpy(nome,n);strcpy(iva,iv);fatturato=fatt;
                     }
        void print(){
            printf("Id[%d] Nome[%s] Iva[%s] Fatturato[%f]\n",id,nome,iva,fatturato);
             
             }
        };
typedef struct clienti{
        tcliente cliente;
        clienti* next;
        clienti(){cliente=tcliente();
        next=NULL;
                  }
        clienti(tcliente c,clienti* n){
        cliente=c;
        next=n;      }
                        void print(){
                             cliente.print();
                             }
        };
This is basic structure in my header 
file


the main is smth like #include <cstdlib>
#include <iostream>
#include "az.h"
#include <string>
#define N 2
using namespace std;

int main(int argc, char *argv[])
{   int fi;
    tcliente d;
    clienti* l;
    clienti* azienda1=NULL;
    clienti* azienda2=NULL;

  stampa(azienda1);
  stampa (azienda2);
    //azienda1->next=azienda2;
    //stampa(azienda1);
  srand (time(NULL));
    //azienda1->print();
    int i;
    stampa(azienda1);
    for(i=0;i<N;i++){
                     d.fatturato=random(1,100)*1000;
                     d.id=i+1;
                     cout<<"Nome cliente"<<endl;
                     gets(d.nome);
                     cout<<"IVA?"<<endl;
                     gets(d.iva);
                     fi=random(1,10);
                     if(fi>6){azienda1=new clienti(d,azienda1);}else{azienda2=new clienti(d,azienda2);}
                     //cout<<f;
                     //stampa(azienda1);
                     //stampa(azienda2);
                              }
                              cout<<"AZIENDA1"<<endl;
                                stampa(azienda1);  
                                 cout<<"AZIENDA2"<<endl;      
                                 stampa(azienda2);
random is a generic psedo-randam int generator


hope u can help me
Topic archived. No new replies allowed.