/*
can yoou please tell me what is wrong with this linklist? i think it is overiding during my read.But how to fix it?
*/
// Created by: Pierre-Michel Jean-Louis
// Date: Febuary 29th 2003
// File name: exercise2.cc
// Purpose: Reads linklist to a file
// input: list.txt
// output: onscreen
# include <iostream.h>
# include <fstream.h>
# include <iomanip.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# include <stddef.h>
# include <math.h>
struct nodetype;
typedef int itemtype;
typedef nodetype * ptrtype;
struct nodetype
{
itemtype item;
ptrtype link;
};
int main()
{
ptrtype head;
ptrtype newp;
ptrtype currentp;
itemtype temp;
ifstream file;
file.open("list.txt");
head = new nodetype;
file >> head->item;
if (file)
{
currentp = head;
file >> temp;
while (file)
{
newp = new nodetype;
newp->item = temp;
currentp->link = newp;
file >> temp;
}
currentp->link = NULL;
}
else
head = NULL;
currentp = head;
while(currentp != NULL)
{
cout << currentp->item <<endl;
currentp = currentp->item;
}
return 0;
}



LinkBack URL
About LinkBacks


