Advertisement
Tiger6117

Reading Data From CSV File Using Linked List

Jun 4th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. /*
  2.     Code a program which gets user data from csv file and then show it to us.
  3.     Saving of each data will be taken in link list as storage data
  4.     Program Coded For BS-CS 2nd Semester - UOS
  5.     by Ñasir Ali
  6.     For more Coding and tricky stuff visit :
  7.     www.tigerzplace.com
  8.     www.softwarezcity.ml
  9.     www.thenavrock.com
  10.                         For Video tutorials Jump here :
  11.                         www.youtube.com/user/t1g3r6117
  12. Thanks :)
  13. */
  14.  
  15.  
  16. // Download this coded program @ : https://www.mediafire.com/?csux1snqbavxcya
  17.  
  18. #include <iostream> //will be use for cout and cin objects
  19. #include <fstream> //for using the input file function
  20. #include <string> //included here to use getline function later on
  21. #include <conio.h> //to use the getch() function so after creating exe file it catches the screen for us :)
  22. using namespace std;
  23.  
  24. struct node{
  25.     string data;
  26.     node *link;
  27. };
  28.  
  29.  
  30. int main()
  31. {
  32.     int r;
  33.     string d,a,age,g;
  34.     node *start=NULL,*cur,*temp; //we will keep address of node members , that's why I choose node data type pointers
  35. ifstream file ( "database.csv" ); //this line opens the file mentioned here
  36.  
  37. if(!file){
  38.     cout << "'Database.csv' not found !!!!";
  39. }
  40.  
  41. while (!file.eof())
  42.     {
  43.         getline(file,d); //this will grab the whole first line from databasae.csv file
  44.         if(start==NULL){
  45.         start=new node;
  46.         start->data=d;
  47.         start->link=NULL;
  48.         }
  49.         else{
  50.             cur=start;
  51.             //this while loop will go to the end
  52.             while(cur->link!=NULL){
  53.             cur=cur->link;
  54.         }
  55.  
  56.         temp=new node;
  57.         temp->data=d;
  58.         cur->link=temp;
  59.         temp->link=NULL;
  60.  
  61. }
  62. }//All Data is Picked from Database.csv
  63.  
  64. //Printing Starts here
  65. cur=start;
  66. cout << "\t\t\tStudents Record \n\n\n";
  67. cout<<"Roll#, Name, Gender, Age, Address\n\n";
  68.  
  69. while(cur->link!=NULL){
  70. cout<< cur->data <<endl;
  71.  
  72. cur=cur->link; //Incrementing in the address pointing
  73. }
  74. file.close();
  75. getch();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement