View Single Post
Old Sep 2nd, 2004, 11:50 AM   #2
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,671
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
dont know exactly what i was doing wrong as i havent taken time to compare the code that i was give but here is what works

// file: main.cpp
// author: Kyle Kjorsvik
// date: 8/31/04
// class: CSIS 352

// This is the file that contains the main function for assignment 1.

#include <iostream>
#include <fstream>
#include <string>
#include "date.h"
//#include "inout.h"
//#include "agecalc.h"
//#include "data.h"

using namespace std;

struct birthdate{
  string name;
  string bdate;
};

int main() {
  const int maxvalue = 10;
  birthdate bd[maxvalue + 1];
  int i = 0, j;

  ifstream inFile("data");
  if (inFile.fail()) {
    cerr << "An error occurred. Unable to read input file." << endl;
    exit(1);
  }
  cout << "File opened" << endl;

  while(!inFile.eof() && i < maxvalue) {
    getline(inFile, bd[i].name, ',');
    getline(inFile, bd[i].bdate);
    ++i;
  }
  inFile.close();

  for (j=i-1; j>=0; j--){//print backwards for giggles
    cout << "\t" << bd[j].name << "\t" << bd[j].bdate << endl;
  }

  return 0;
}
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote