All pastes #1532864 Raw Edit

eric

public text v1 · immutable
#1532864 ·published 2009-08-17 19:05 UTC
rendered paste body
#include <iostream>
#include <fstream>
#include <cstring>




using namespace std;


	
	
	void shiftBuffer(char [], int);	
	void clearBuffer(char [], int);
	int customStrCmp(char [], char [], int);	
	void print(char []);	


	//global variables
	ofstream output;
	char writefile[80];
					
	void fillList() {
		
		//filename to open
		char filename[40];
		
		//keys
		char classNameKey[] = "classKEY";
		//char classNameKeyEnd[] = 'classEnd';
		
		char daysKey[] = "daysKEY";
		//char daysKeyEnd[] = 'dayEnd';
		
		char timesRangeKey[] = "times";
		//char timesRangeKeyEnd[] = 'timeEnd';
		
		char seatsTotalKey[] = "totalseats";
		//char seatsTotalKeyEnd[] = 'totalEnd';
		
		char seatsOpenKey[] = "openSeats";
		//char seatsOpenKeyEnd[] = 'openEnd';
		
		char profNameKey[] = "profName";
		//char profNameKeyEnd[] = 'nameEnd'; 
		
		
		//key end
		char keyEnd = '<';
		
		//buffer
		char readBuffer[51];
		readBuffer[50] = '\0';
		
		//data
		char className[20];
		char days[30];
		char timesRange[9];
		char seatsTotal[20];
		char seatsOpen[20];
		char profNamme[50]; 
        
        
        cout <<"Enter the name of the file containg the data you want to read: ";
        cin >> filename;
        
        
        //initialize the input stream
        ifstream input;
        
        //open the file to read the data  from
        input.open(filename);
        
        //if the file cannot be found, show this to the user.
        if(input.fail()) 
    		cout << "The desired file was not found, sorry." << endl;
        
        
       clearBuffer(readBuffer,49);
        while (!input.eof()) {
			//read the data one character at a time	
			//out <<"Getting here" << endl;
			shiftBuffer(readBuffer,49);
			input >> readBuffer[49];
			
			//print(readBuffer);
			
			//check to see if any of the keys match the buffer
			if (customStrCmp(readBuffer,classNameKey,42)) {
				//cout <<"getting here2" << endl;
				char temp;
				int index = 0;
				input >> temp;
				while (temp != keyEnd){
					className[index] = temp;
					input >> temp;
					index++;
				}
				className[index] = '\0';
				//cout << "The class name is: ";
				//print(className);
				output << '"' << className << '"' << ',';
				clearBuffer(readBuffer,49);
			}
			
			//cout << "ARE WE GETTING HERE?" << endl<<endl<<endl;
			
			if (customStrCmp(readBuffer,timesRangeKey,45)) {
				cout <<"getting here3" << endl;
				char temp;
				int index = 0;
				input >> temp;
				while (temp != keyEnd){
					timesRange[index] = temp;
					input >> temp;
					index++;
				}
				timesRange[index] = '\0';
				//cout << "The time range is: ";
				//print(timesRange);
				output << '"' << timesRange << '"' << ',';
				clearBuffer(readBuffer,49);
			}
		
		
		}
}


int main(void) {

cout<<"Input the name of the file that you would like to write to: ";
cin >> writefile;
output.open(writefile);
char goOn;

do{
	fillList();
	cout << "Type c to continue." <<endl;
	cin >> goOn;
}while(goOn == 'c');

output.close();
return 1;
}



void shiftBuffer(char buffer[], int bufferSize) {
for (int i=1;i<=bufferSize;i++)
	buffer[i-1] = buffer[i];
}
	 
void clearBuffer(char buffer[], int bufferSize) {
for (int i=0;i<=bufferSize;i++)
		buffer[i] = 'o';
}
 
 
int customStrCmp(char bufferedString[], char keyString[], int startIndex) {
	int counter = 0;
	for(int i=startIndex;i<=49;i++) {
		if (bufferedString[i] != keyString[counter])
			return 0;
		counter++;	
	}
		return 1;
}

void print(char string[]) {
		int index = 0;
		while (string[index] != '\0'){ 
			cout<< string[index];
			index++;
			}
			
		cout << endl;
}