I'm trying to get some data from a text file into a linked list using pointers so I can print the data out. Here's the code I have.
Code:
#include <iostream>
#include <fstream>
#include <string> //List is a list of names
#include <cstddef> //For NULL
using namespace std;
struct nodeType
{
string name[10];
nodeType* link;
};
void CreateList(nodeType* &head, ifstream& infile);
void PrintList(nodeType* head);
int main()
{
ifstream infile;
infile.open("infile.txt");
nodeType* head = NULL;
if(!infile)
{
cout << "The file does not exist.";
return 0;
}
CreateList(head, infile);
PrintList(head);
return 0;
}
void CreateList (nodeType* &head, ifstream& infile)
{
head = NULL;
}
//
void PrintList (nodeType* head)
{
nodeType* currptr = head;
while (currptr != NULL)
{
for(int i = 0; i < 10; i++)
cout << head -> name[i] << endl; //I think this is the problem
currptr = currptr -> link;
}
}