All pastes #764949 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2007-11-07 18:19 UTC
rendered paste body
#include <iostream>#include <cmath>#include <iomanip>#include <cstdlib>#include <fstream>using namespace std;char filePath[128] = "test.txt";int main(){int size = 4;char *ptr = NULL;char **keys = new char*[size];char **values = new char*[size];system("clear");cout << "*** Time to Parse! ***\n" << endl;cout << "Input file path: ";//cin >> filePath;cout << "\n\n\n"; int count = 0;char tempChar[256];fstream file(filePath, ios::in);if(file.is_open()){	while(!file.eof()){	file.getline (tempChar, 256,'\n');	ptr = strtok(tempChar, ":&");		while (ptr != NULL)	{		if(count%2 == 0){		*(keys + (count/2)) = new char[strlen(ptr)+1];		strcpy(*(keys + (count/2)),ptr);		}else{		*(values + (count/2)) = new char[strlen(ptr)+1];		strcpy(*(values + (count/2)),ptr);		}	ptr = strtok(NULL, ":&");	//cout << count/2 << endl;     	    if ((count/2) + 1 > size) {       		char** temp = new char*[size];		char** temp2 = new char*[size]; 		        for (int x=0; x<(count/2); x++) {            temp[x] = keys[x]; 			temp2[x] = values[x];          }		size = size + 3;   		char** keys = new char*[size];		char** values = new char*[size]; 				for (int x=0; x<(count/2); x++) {            keys[x] = temp[x];    			values[x] = temp2[x];               }						      }		count++;	}			}file.close();}/*for(int x = 0; x < (count/2); x++){cout << x << ": "; 	cout << *(keys + x);	cout << " = ";	cout << *(values + x) << endl;}*///for(int x = 0; x < (count/2); x++){//delete [] (keys[x]);//delete [] (values[x]);//}return 0;}