![]() |
| ||
| passing linked lists through functions?? Hello, I am trying to call two functions: one that pulls data from a file and stores into a linked list, and one that displays this data to the screen. I pulled my code out of the functions and created a new file and included everything in the main function, and everything worked (the reading in of data and displaying to screen). Sooo...that led me to believe that the problem lies in passing the linked list between the functions. Any idea what I could be doing wrong?? (I left out the other functions in the program for now). Thanks in advance for your help!
|
| ||
| Re: passing linked lists through functions?? The problem is in Read_File, you have to pass listTop pointer by reference so that Read_File() can change the value of the pointer that was created in main(). void Read_File(resident *& listTop, int &residentCount)Next problem with that function -- delete the declaration of listTop at line 47 because it is a duplicate definition of the parameter and your compiler should have given you an error about that. The loop at line 67 is constructed wrong -- it should be a while loop, not a do loop (which means you can delete the if statement on line 71) while( inFile >> oneSsn >> oneFirstInitial >> oneLastName >> onePhoneNum >> temp ) |
| ||
| Re: passing linked lists through functions?? Thanks Ancient Dragon, (I will number my lines from now on!)... I changed the pointer to be passed as a reference. That definitely helped read in the data from the file. My output still isn't working, but I had to do a mini-display elsewhere in my program that worked. So, I just need to take another look at my display function now. I will try and figure that one out today though. Thanks again for your help! |
| All times are GMT -4. The time now is 3:17 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC