With the kind of syntax errors it is letting him get away with it almost undoubtedly is TurboC...
Don't use C style headers. Use instead C++ headers.
#include <iostream>
#include <fstream>
#include <cassert>
Personally, I can't stand all the assert stuff people throw in their code for minor errors... but seeing as you don't use any you don't need to include the header...
The
main() function
always returns an
int. At the very least it should look like this:
int main()
{
// do stuff here
return EXIT_SUCCESS;
}
The
ifstream class does not need to be told not to create a file. (But
ios::nocreate is non-standard anyway.) Just say:
instream.open( filename );
OK, on to logic errors.
First, you need to be much more careful how you handle your linked list nodes. You've got dangling pointers.
Use function arguments to create a node, not global variables. This will help fix your errors. For example, create a function named:
Line *add_node( char *text, Line *prev, Line *next );
All this function should do is create a
new node and fill it with the information given to it.
This forces you to separate your linked list code from handling global variables. To create the first node in the list, just say
head = tail = add_node( "I am first", NULL, NULL );
You can append a node in a similar way:
tail = add_node( "I am not first", tail->prev, NULL );
The reason your output is full of funny characters is because you have not initialized your char[80] string properly. This is because you are reading until you get to the end of line but otherwise not terminating your string or clearing it of characters already there. A slight "animation", as it were:
xy--ze===gobbledegook...ze (line as it is when you start the program)
Wy--ze===gobbledegook...ze
Wh--ze===gobbledegook...ze
Whe-ze===gobbledegook...ze
Whenze===gobbledegook...ze
When e===gobbledegook...ze
When I===gobbledegook...ze
When I ==gobbledegook...ze
When I s=gobbledegook...ze
etc...
See what is happening? To read lines from file, instead use something like:
char reading[ 80 ];
instream.getline( reading, 80 );
This will read a maximum of 79 characters into a
reading string and guarantee that it is null-terminated. You can then copy this string into a node using
add_node().
Hope this helps.