Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ifstream inStream; // declare an input file stream
- int year= 1880;
- char c; // input character
- int i; // loop counter
- int number = 0; // Used to store numbers read in
- Node *pStart = NULL; // head of linked list
- Node *tempPtr; // Temporary node pointer used in reversing list
- int menuChoice; // Menu choice
- for(i=1880; i <= 2009; ++i){
- FILE *fp;
- char filename[12];
- sprintf (filename, "yob%i.txt", year);
- fp=fopen(filename, "r"); // open in "r"ead mode
- // open input file
- if ( fp == NULL ) {
- cout << "Input file opening failed. Exiting...\n\n";
- exit(-1);
- }
- char inputLine[ 90];
- char name[ 20];
- char gender;
- int count;
- while( fscanf(fp, "%s", inputLine) != EOF) { // read a line of input
- char *pStart = inputLine;
- char *pEnd = NULL;
- // Pull out the name
- pEnd = strchr( inputLine, ',');
- int length = pEnd - inputLine;
- strncpy( name, pStart, length);
- cout << "Name is: " << name << endl;
- // advance the start pointer to the position after the name after the ','
- pStart = pEnd+1;
- gender = *pStart;
- cout << "Gender is: " << gender << endl;
- // again advance the start pointer to the character past the ','
- pStart += 2;
- count = atoi( pStart);
- cout << "Count value is: " << count << endl;
- year++;
- }
- cout << "Done. " << endl;
- system("pause");
- // Printing the data on screen
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement