title: Print List function is not outputting data from CSV file
body: <p>I am working on a Linked List assignment. The Load Bids function extracts the data from the CSV file. The Print List function is supposed to print all the bid entries in the list to the console. For some reason, whenever I select the Load Bids option, and then the Print List option from menu, the Print List function is not outputting data, even after I call the Load Bids function. It just prints the default values from the default constructor, which is basically nothing. The Print List function seems to be written correctly, but the data appears to be getting lost somewhere. Can someone help me with this?</p>
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  #include &lt;time.h&gt;
  
  #include &quot;CSVparser.hpp&quot;
  
  using namespace std;
  
  //============================================================================
  // Global definitions visible to all methods and classes
  //============================================================================
  
  // forward declarations
  double strToDouble(string str, char ch);
  
  // define a structure to hold bid information
  struct Bid {
    string bidId; // unique identifier
    string title;
    string fund;
    double amount;
    Bid() {
      amount = 0.0;
   }
  };
  
  //============================================================================
  // Linked-List class definition
  //============================================================================
  
  /**
   * Define a class containing data members and methods to
   * implement a linked-list.
   */
  class LinkedList {
  
  private:
    //Internal structure for list entries, housekeeping variables
    struct Node {
      Bid bid;
      Node *next;
  
      // default constructor
      Node() {
          next = nullptr;
      }
  
      // initialize with a bid
      Node(Bid aBid) {
          bid = aBid;
          next = nullptr;
      }
  };
  
  Node* head;
  Node* tail;
  int size = 0;
  
  public:
    LinkedList();
    virtual ~LinkedList();
    void Append(Bid bid);
    void Prepend(Bid bid);
    void PrintList();
    void Remove(string bidId);
    Bid Search(string bidId);
    int Size();
  };
  
  /**
   * Default constructor
   */
  LinkedList::LinkedList() {
    // FIXME (1): Initialize housekeeping variables
    //set head and tail equal to null
    head = nullptr;
    tail = nullptr;
  }
  
  /**
   * Destructor
   */
  LinkedList::~LinkedList() {
    // start at the head
    Node* current = head;
    Node* temp;
  
    // loop over each node, detach from list then delete
    while (current != nullptr) {
      temp = current; // hang on to current node
      current = current-&gt;next; // make current the next node
      delete temp; // delete the orphan node
    }
  }
  
  /**
   * Append a new bid to the end of the list
   */
  void LinkedList::Append(Bid bid) {
    // FIXME (2): Implement append logic
    //Create new node
    Node* new_node = new Node;
    //if there is nothing at the head...
    if (head == nullptr) {
      // new node becomes the head and the tail
      head = new_node;
      tail = new_node;
      
    }
  //else 
  else {
      // make current tail node point to the new node
      tail-&gt;next = new_node;
      // and tail becomes the new node
      tail = new_node;
  }
  //increase size count
  size++;
  }
  
  /**
   * Prepend a new bid to the start of the list
   */
  void LinkedList::Prepend(Bid bid) {
    // FIXME (3): Implement prepend logic
    // Create new node
    Node* new_node = new Node;
    // if there is already something at the head...
    if (head != nullptr) {
      // new node points to current head as its next node
      new_node-&gt;next = head;
    }
  // head now becomes the new node
  head = new_node;
  //increase size count
  size++;
  }
  
  /**
   * Simple output of all bids in the list
   */
  void LinkedList::PrintList() {
    // FIXME (4): Implement print logic
    // start at the head
    Node* current = head;
    // while loop over each node looking for a match
    while (current != nullptr) {
      //output current bidID, title, amount and fund
      cout &lt;&lt; current-&gt;bid.bidId &lt;&lt; &quot; | &quot;;
      cout &lt;&lt; current-&gt;bid.title &lt;&lt; &quot; | &quot;;
      cout &lt;&lt; current-&gt;bid.amount &lt;&lt; &quot; | &quot;; 
      cout &lt;&lt; current-&gt;bid.fund &lt;&lt; endl;
      //set current equal to next
      current = current-&gt;next;
    }
  }
  
  /**
   * Remove a specified bid
   *
   * @param bidId The bid id to remove from the list
   */
  void LinkedList::Remove(string bidId) {
    // FIXME (5): Implement remove logic
    // special case if matching node is the head
    if (head-&gt;bid.bidId == bidId) {
        // make head point to the next node in the list
        head-&gt;next;
        //decrease size count
        size--;
        //return
        return;
    }
  
  // start at the head
  Node* current = head;
  Node* temp = nullptr;
  // while loop over each node looking for a match
  while (current != nullptr) {
      // if the next node bidID is equal to the current bidID
      if (current-&gt;next-&gt;bid.bidId == current-&gt;bid.bidId) {
          // hold onto the next node temporarily
          temp = current-&gt;next;
      }
       // make current node point beyond the next node
      current-&gt;next-&gt;next;
       // now free up memory held by temp
      free(temp);
       // decrease size count
      size--;
       //return
      return;
  }
  
  // curretn node is equal to next node
  current = current-&gt;next;
  }
  
  
  
  /**
   * Search for the specified bidId
   *
   * @param bidId The bid id to search for
   */
  Bid LinkedList::Search(string bidId) {
    // FIXME (6): Implement search logic
  
    // special case if matching node is the head
    if (head-&gt;bid.bidId == bidId) {
      // make head point to the next node in the list
      head-&gt;next;
      //decrease size count
      size--;
      //return
      return head-&gt;bid;
  }
  // start at the head of the list
  Node* current = head;
  
  // keep searching until end reached with while loop (next != nullptr
  while (current != nullptr) {
      // if the current node matches, return it
      if (current-&gt;bid.bidId == bidId) {
          return current-&gt;bid;
      }
          // else current node is equal to next node
      else {
          current = current-&gt;next;
      }
  }
   //return bid
  return current-&gt;bid;
  }
  
  /**
   * Returns the current size (number of elements) in the list
   */
  int LinkedList::Size() {
    return size;
  }
  
  //============================================================================
  // Static methods used for testing
  //============================================================================
  
  /**
  * Display the bid information
   *
   * @param bid struct containing the bid info
   */
  void displayBid(Bid bid) {
    cout &lt;&lt; bid.bidId &lt;&lt; &quot;: &quot; &lt;&lt; bid.title &lt;&lt; &quot; | &quot; &lt;&lt; bid.amount
       &lt;&lt; &quot; | &quot; &lt;&lt; bid.fund &lt;&lt; endl;
    return;
  }
  
  /**
  * Prompt user for bid information
   *
   * @return Bid struct containing the bid info
   */
  Bid getBid() {
    Bid bid;
  
    cout &lt;&lt; &quot;Enter Id: &quot;;
    cin.ignore();
    getline(cin, bid.bidId);
  
    cout &lt;&lt; &quot;Enter title: &quot;;
    getline(cin, bid.title);
  
    cout &lt;&lt; &quot;Enter fund: &quot;;
    cin &gt;&gt; bid.fund;
  
    cout &lt;&lt; &quot;Enter amount: &quot;;
    cin.ignore();
    string strAmount;
    getline(cin, strAmount);
    bid.amount = strToDouble(strAmount, '$');
  
    return bid;
  }
  
  /**
   * Load a CSV file containing bids into a LinkedList
   *
   * @return a LinkedList containing all the bids read
   */
  void loadBids(string csvPath, LinkedList *list) {
      cout &lt;&lt; &quot;Loading CSV file &quot; &lt;&lt; csvPath &lt;&lt; endl;
  
      // initialize the CSV Parser
      csv::Parser file = csv::Parser(csvPath);
  
     try {
      // loop to read rows of a CSV file
      for (int i = 0; i &lt; file.rowCount(); i++) {
  
          // initialize a bid using data from current row (i)
          Bid bid;
          bid.bidId = file[i][1];
          bid.title = file[i][0];
          bid.fund = file[i][8];
          bid.amount = strToDouble(file[i][4], '$');
  
         // cout &lt;&lt; bid.bidId &lt;&lt; &quot;: &quot; &lt;&lt; bid.title &lt;&lt; &quot; | &quot; &lt;&lt; bid.fund &lt;&lt; &quot; | &quot; &lt;&lt; 
   bid.amount &lt;&lt; endl;
  
          // add this bid to the end
          list-&gt;Append(bid);
      }
  } catch (csv::Error &amp;e) {
      std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
    }
  }
  
   /**
   * Simple C function to convert a string to a double
   * after stripping out unwanted char
   *
   * credit: http://stackoverflow.com/a/24875936
   *
   * @param ch The character to strip out
   */
  double strToDouble(string str, char ch) {
    str.erase(remove(str.begin(), str.end(), ch), str.end());
    return atof(str.c_str());
  }
  
  /**
  * The one and only main() method
  *
  * @param arg[1] path to CSV file to load from (optional)
   * @param arg[2] the bid Id to use when searching the list (optional)
  */
  int main(int argc, char* argv[]) {
  
    // process command line arguments
    string csvPath, bidKey;
  switch (argc) {
  case 2:
      csvPath = argv[1];
      bidKey = &quot;98109&quot;;
      break;
  case 3:
      csvPath = argv[1];
      bidKey = argv[2];
      break;
  default:
      csvPath = &quot;eBid_Monthly_Sales_Dec_2016.csv&quot;;
      bidKey = &quot;98109&quot;;
  }
  
  clock_t ticks;
  
  LinkedList bidList;
  
  Bid bid;
  
  int choice = 0;
  while (choice != 9) {
      cout &lt;&lt; &quot;Menu:&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;  1. Enter a Bid&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;  2. Load Bids&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;  3. Display All Bids&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;  4. Find Bid&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;  5. Remove Bid&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;  9. Exit&quot; &lt;&lt; endl;
      cout &lt;&lt; &quot;Enter choice: &quot;;
      cin &gt;&gt; choice;
  
      switch (choice) {
      case 1:
          bid = getBid();
          bidList.Append(bid);
          displayBid(bid);
  
          break;
  
      case 2:
          ticks = clock();
  
          loadBids(csvPath, &amp;bidList);
  
          cout &lt;&lt; bidList.Size() &lt;&lt; &quot; bids read&quot; &lt;&lt; endl;
  
          ticks = clock() - ticks; // current clock ticks minus starting clock ticks
          cout &lt;&lt; &quot;time: &quot; &lt;&lt; ticks &lt;&lt; &quot; milliseconds&quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;time: &quot; &lt;&lt; ticks * 1.0 / CLOCKS_PER_SEC &lt;&lt; &quot; seconds&quot; &lt;&lt; endl;
  
          break;
  
      case 3:
          bidList.PrintList();
  
          break;
  
      case 4:
          ticks = clock();
  
          bid = bidList.Search(bidKey);
  
          ticks = clock() - ticks; // current clock ticks minus starting clock ticks
  
          if (!bid.bidId.empty()) {
              displayBid(bid);
          } else {
              cout &lt;&lt; &quot;Bid Id &quot; &lt;&lt; bidKey &lt;&lt; &quot; not found.&quot; &lt;&lt; endl;
          }
  
          cout &lt;&lt; &quot;time: &quot; &lt;&lt; ticks &lt;&lt; &quot; clock ticks&quot; &lt;&lt; endl;
          cout &lt;&lt; &quot;time: &quot; &lt;&lt; ticks * 1.0 / CLOCKS_PER_SEC &lt;&lt; &quot; seconds&quot; &lt;&lt; endl;
  
          break;
  
      case 5:
          bidList.Remove(bidKey);
  
          break;
      }
  }
  
  cout &lt;&lt; &quot;Good bye.&quot; &lt;&lt; endl;
  
  return 0;
  }
  </code></pre>