Read problems

This is a discussion on Read problems within the C++ Programming forums, part of the General Programming Boards category; I'm having troubles getting the read to work.
I feel this should work.
It doesn't get past the anoted location ...

I have problems with the order of read.

Thank you for replying I was starting to think nobody would.
I'm trying to input a freshly read binary file into a uncreated linked list. I have it simiworking. It reads the first name, last name, and ssnumber. It doesn't read the integers weight or age that have been read. Does it need to be inputed into the file in a certain order and read in a certain order?

strncpy();

I didn't think of strncpy(); that sounds a lot better.
I tried to read directly into the the link pointer, but it didn't work.
I have 3 char arrays (fname, lname, ssnumber) and 2 ints (age, weight). In the binary file after write it shows a blank space after the inputed data. does that mean it has a newline?

Is there any reason to use a binary file? Because normally when you write a binary file, you write the whole link struct in one write.

I believe the problem is, you are not outputting a space between each item. Then when you use the >> operator to read, it looks for a space or newline between each item. To do this, you write function would look like:

Re: binary file

Originally posted by xviddivxoggmp3 I was advised that I would have a lower memory overhang by using a binary file. Is this true. It was phrased to me as lower file size and less cpu usage. Is this true?

I doubt this is true, unless you write out the whole link struct in one shot. Like this:

outstream.write(reinterpret_cast <char *> current, sizeof(*current));

Then to read each node from the file, use:
outstream.read(reinterpret_cast <char *> current, sizeof(*current));

[Edit]
The below code is my working code, but I tried to rewrite the read to resemble the write to eliminate unneeded code, but it didn't work. Please compare the working with my non-working version located underneith it to see if you have any input. Thanks.
basically what all the crap below is saying is that i'm having problems reading (instream>>newlink->fname;) It requires me to loop it and increment each individual location of the array to input the read info. Should it not allow the simple read like the write does?
[/Edit]

the out put shows garbage in the first print.
see the output below. I want it to be more stream lined, but it looks like the only option is to go back to the working code.
why can I not read the same as write?

-----------------------------------------------------------------------------------
Build and Display a linked list
1) Add an Item to the front of the list
2) Add an Item to the end of the list
3) Display the list
4) Number of nodes in the list
5) Create an ordered list
6) Delete a node (node n)
7) Delete a node (by key)
8) Destroy the list
9) Insert a node anywhere
10) Write to file
11) Read file
12) Quit this stuff
Enter an option: 3
The linked list looks like this so far
Head ->

xviddivxoggmp3, you're too kind .
I'm not exactly sure what you are doing with the links in your read() function. Correct me if I'm wrong, but shouldn't head point to the first link, and tail point to the last link?

I did some testing, and after a couple hiccups, seemingly got a read() function working. I'll post my read(). The big difference is the linked list part. Also it's missing the initializeData(), since I don't know what that does. I'll leave the cout's in there.

One note. In my read(), I read the fname within the while. Typically if you don't do this, you'll get an extra read, because eof() doesn't become true until a read is attempted at eof. It won't hurt to leave it the way you have it for now, but something to consider if you get an extra link.