Article View: csu.cs.200
Article #161Re: Need notes from class- void read_load_list(...)
From: Melissa Jackson
Date: Tue, 15 Sep 1998 00:00
Date: Tue, 15 Sep 1998 00:00
50 lines
1773 bytes
1773 bytes
Here is what I had in my notes. We had not gone into DNM and NDNM when we did
this example. So this is the NDNM.
//Given: Variable to hold head pointer, filename
//Result: Read contents file, store in linked list whose first node is pointed
to by headptr
void Read_Load_list(SLLnode *&headptr, charinfile[])
{
ifstream in;
bool first=TRUE;
SLLnode *newptr, *prevptr;
int temp;
//open file
in.open(infile);
in>>temp;
while(!in.eof())
{
newptr=new SLLnode;
newptr->field1=temp;
//Read
in>>newptr->field2>>newptr->field3;
newptr->next=NULL;
if(first)
{
headptr=newptr;
first=FALSE;
}
else
{
prevprt->next=newptr;
}
prevptr=newptr;
in>>temp;
}//while
in.close();
}//Read_Load_List
Chris Vaughn-Uding wrote:
> I've been having a little bit of trouble reading my notes about reading in
> from a file to a linked list. I'm getting confused on which parts are DNM
> and NDNM. If anyone has either method I would appreciate if they could post
> it. My notes list the function name as
> void read_load_list(SLLnode *&headptr, char infile[ ])
> We wrote the whole thing out in class and it would help give me some
> direction on assn#2.
>
> Thanks,
> Chris Vaughn
Technical Details
Message-ID:
<35FE80CB.8459FF03@holly.colostate.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6thplo$38s8@yuma.ACNS.ColoState.EDU>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 127144,683e602360e44e31 X-Google-Attributes: gid127144,public From: Melissa Jackson <maj@holly.colostate.edu> Subject: Re: Need notes from class- void read_load_list(...) Date: 1998/09/15 Message-ID: <35FE80CB.8459FF03@holly.colostate.edu> X-Deja-AN: 391365652 Content-Transfer-Encoding: 7bit References: <6thplo$38s8@yuma.ACNS.ColoState.EDU> Content-Type: text/plain; charset=us-ascii Organization: Colorado State University, Fort Collins, CO 80523 Mime-Version: 1.0 Newsgroups: csu.cs.200