why can't i read file data into my linked list?

i am working on a movie database and i have output from my file that i want to load into my linked list,no problem opening file but when i run this function it goes into infinite loop.

i am reading this from the txt file
SHAWSHANK REDEMPTION 120 5 MYSTERY 2009 ENGLISH 3
THE MATRIX 120 5 MYSTERY 2009 ENGLISH 3
THE MATRIX PART1 120 5 MYSTERY 2009 ENGLISH 3
THE MATRIX PART2 120 5 MYSTERY 2009 ENGLISH 3

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
#include<cstdio>
#include<cstdlib>
#include<string>
#include<fstream>
/*
 * Node Declaration
 */
using namespace std;
struct node
{
    int info;
    string name;
    string genre;
    string language;
    int release_year;
    int amount;
    int rating;
    int runtime;
    struct node *next;
    struct node *prev;
    static int counter;
}*start;
int id=1;
/*
 Class Declaration
 */
class double_llist
{
    public:

        void create_list(string mname,
    string mgenre,
    string mlanguage,
    int mrelease_year,
    int mamount,
    int mrating,int mruntime);

        void add_begin(string mname,
    string mgenre,
    string mlanguage,
    int mrelease_year,
    int mamount,
    int mrating,int mruntime);


        void add_after(int value, int position,
    string mname,
    string mgenre,
    string mlanguage,
    int mrelease_year,
    int mamount,
    int mrating,int mruntime);
        void delete_element(int value);
        void search_element(node *head, int value);
        void display_dlist();
        void sort();
        int count();
        void reverse();
        void savetofile();
        void loadfromfile();
        double_llist()
        {
            start = NULL;

        }
};

create node function
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
void double_llist::create_list(string mname,
    string mgenre,
    string mlanguage,
    int mrelease_year,
    int mamount,
    int mrating,int mruntime)
{

    struct node *s, *temp;
    temp = new(struct node);
    temp->info=id++;
    temp->name = mname;
    temp->genre=mgenre;
    temp->language=mlanguage;
    temp->release_year=mrelease_year;
    temp->amount=mamount;
    temp->rating=mrating;
    temp->runtime=mruntime;
    temp->next = NULL;
    if (start == NULL)
    {
        temp->prev = NULL;
        start = temp;
    }
    else
    {
        s = start;
        while (s->next != NULL)
            s = s->next;
        s->next = temp;
        temp->prev = s;
    }
}



load from file method

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
  
void double_llist::loadfromfile()
{
    string mname;
    string mgenre;
    string mlanguage;
    int mrelease_year;
    int minfo;
    int mamount;
    int mrating;
    int mruntime;
    ifstream input;
    input.open("database.txt");
    struct node *s, *temp;
    temp = new(struct node);
    while(!input.eof()){
        input>>info>>mname>>mgenre>>mlanguage>>mrelease_year>>mamount>>mrating>>mruntime;
     create_list(mname,
    mgenre,
    mlanguage,
    mrelease_year,
    mamount,
    mrating,mruntime);
        temp->next = NULL;
        }
        input.close();

}

Last edited on
Topic archived. No new replies allowed.