SHARE
TWEET

Untitled

a guest Aug 13th, 2017 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  ifstream inStream;             // declare an input file stream
  2.    
  3.         int year= 1880;
  4.    char c;                        // input character
  5.    int i;                         // loop counter
  6.    int number = 0;      // Used to store numbers read in
  7.    Node *pStart = NULL;   // head of linked list
  8.    Node *tempPtr;       // Temporary node pointer used in reversing list
  9.    int menuChoice;      // Menu choice
  10.    
  11.    for(i=1880; i <= 2009; ++i){
  12.            
  13.    FILE *fp;
  14.      char filename[12];
  15.      sprintf (filename, "yob%i.txt", year);
  16.      fp=fopen(filename, "r"); // open in "r"ead mode
  17.      
  18.     // open input file
  19.     if ( fp == NULL ) {
  20.     cout << "Input file opening failed. Exiting...\n\n";
  21.     exit(-1);
  22.     }
  23.    
  24.     char inputLine[ 90];
  25.     char name[ 20];
  26.     char gender;
  27.     int count;
  28.    
  29.     while( fscanf(fp, "%s", inputLine) != EOF) { // read a line of input
  30.     char *pStart = inputLine;
  31.     char *pEnd = NULL;
  32.    
  33.     // Pull out the name
  34.     pEnd = strchr( inputLine, ',');
  35.     int length = pEnd - inputLine;
  36.     strncpy( name, pStart, length);
  37.     cout << "Name is: " << name << endl;
  38.     // advance the start pointer to the position after the name after the ','
  39.     pStart = pEnd+1;
  40.     gender = *pStart;
  41.     cout << "Gender is: " << gender << endl;
  42.     // again advance the start pointer to the character past the ','
  43.     pStart += 2;
  44.     count = atoi( pStart);
  45.     cout << "Count value is: " << count << endl;
  46.     year++;
  47.     }
  48.     cout << "Done. " << endl;
  49.     system("pause");
  50.  
  51.      // Printing the data on screen
  52.    }
RAW Paste Data
Top