what am i doing wrong...

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
struct struktura
{
string clan,clan1;
struktura *next;
}

*start, *aktuelni;

int main()
{
int i=1;
string privremeni;

fstream file("zivotinje.txt", ios::in);
while (!file.eof())
{
file >> privremeni;



aktuelni=new struktura();
if (!aktuelni) {cerr << " Nema dovoljno memorije \n ";}
else
{
aktuelni->clan=privremeni;

aktuelni->next=start;
start=aktuelni;

}
}
file.close();
aktuelni=start;
while (aktuelni != NULL)
{
cout<<setw(1)<<""<<aktuelni->clan<<""<<endl;
aktuelni=aktuelni->next;
i++;

}
}


the txt database contains:
1.pas
2.macka
3.konj
4.lav

and it should be listen in that order
I'm not sure what specific problem you are having. I see 2 possibilities.

You are always putting the new structure at the beginning of the list. This will reverse the order of the list in your output.

Also, You are checking for eof before you read from the file. When you read the last string in the file, it will NOT set eof. When you try to read from the file AFTER you've read the last string, eof will be set. This would give you an empty node at the beginning of the list.
Topic archived. No new replies allowed.