About read file and store in an array of linked list

_I have a txt file with the content like this :

5
1.2.10.5.15.
2.1.10.3.17.
3.2.17.4.20.
4.3.20.5.19.
5.4.19.1.15.

_My code is try to read from the file and create an array of linked list to store them (the first line in txt is the sum of object that will be created).After building,it run but there's no thing be shown,anyone can help me.Thanks you all,

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

struct node
{
string name;
int w;
node *next;
};
int convert(string strConvert)
{
int intReturn;
intReturn = atoi(strConvert.c_str());
return(intReturn);
}

int _tmain(int argc, _TCHAR* argv[])
{

int row(0);
int i,j,pre,dot(0);

char *p;
ifstream in;
in.open("data.txt");
if (!in)
{ cout <<"Error in opening data.txt" <<endl; }
else
{
node *head[6];
while (!in.eof())
{
p=new char[20];
if(row==0)
{
++row;
}
else
{
in.get(p,20,'\n');
for(i=0;i<20;++i)
{
if(p[i]=='.')
{
++dot;
if(dot==1)
{
for(j=0;i<p[i];++j)
{ a=a+p[j]; }
head[row]->name=a;
head[row]->next=NULL;
pre=i;
a.clear();
}
else if((dot%2)==0)
{
for(j=pre+1;j<p[i];++j)
{ a=a+p[j]; }
node*temp=head[row];
while(temp->next!=NULL)
temp=temp->next;
temp->next=new node;
temp=temp->next;
temp->w=0;
temp->name=a;
temp->next=NULL;
pre=i;
a.clear();
}
else
{
for(j=pre+1;j<p[i];++j)
{ a=a+p[j]; }
b=convert(a);
node*temp=head[row];
while(temp->next!=NULL)
temp=temp->next;
temp->next=new node;
temp=temp->next;
temp->w=b;
temp->name="0";
temp->next=NULL;
pre=i;
a.clear();
}
}
}
++row;
}
dot=0;
delete [] p;
}

}
cout<<"....";
return 0;}
Last edited on
Topic archived. No new replies allowed.