Yes, please disregard that first bunch of mess of code. Here is an update on how is looking so far:
Code:
Script started on Sun Apr 17 17:29:35 2005
$ cat zipc.cpp
#include <iostream>
#include <cstring>
#include <fstream.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <vector.h>
//----------------------------------------------------------
/* global variable that is number of characters dictionary
starts with */
int NUMELS = 10;
using namespace std;
using std::cout;
using std::endl;
using std::ifstream;
using std::string;//Thanks HighCommander4
using std::vector;
void compressText(vector<int> &, vector<char> &);
//*************************************************************
//*************************************************************
//*************************************************************
//*************************************************************
void compressText(vector<int> &code, vector<char> &key)
{
//----------------------------------------------------------
/* opens input file to read from and checks for errors*/
ifstream input;
input.open("text.txt", ios::nocreate);
if (!input)
{
cerr<<"Error opening file:" <<endl;
return;
}
//----------------------------------------------------------
/* opens output file to hopefully write compressed data to*/
ofstream outdata;
outdata.open("outdata.txt");
//----------------------------------------------------------
char c[20]="";
char buffer[20]="";
char tempString[20]="";
int codeCntr = NUMELS;
int found=0, k;
input.get(*tempString);
strcat(buffer,tempString);
//----------------------------------------------------------
/* reads in data until end of file. for loop checks if data
contained in buffer has been seen before. for now if it has
found a macth it prints a message. If not found it adds the
data in buffer to vector*/
while(!input.eof())
{
input.get(*c);
strcat(buffer,c);
cout<<c <<"<--c value" <<endl;
found=0;
for(k=0;k<=codeCntr;k++)
{
cout<< key[k]<<"<---key value"<<endl;
cout<< buffer<<"<---buffer value"<<endl;
usleep(1600);
if(key[k]==*(buffer)&&found==0)
{
tempString=buffer;
found=1;
cout<<"found it**************" <<endl<<key[k]<<endl;
}
}
if(found==0)
{
codeCntr++;
code.insert(code.begin() + codeCntr,codeCntr);
key.insert(key.begin() + codeCntr,*buffer);
tempString=c;
cout<<"in !found statement" <<endl;
}
}//end while loop
outdata.close();
return;
}
//*************************************************************
int main()
{
int a[NUMELS];
char b[NUMELS];
int i;
//----------------------------------------------------------
//opens text file to compress and checks for opening correct
ifstream indata;
indata.open("text.txt", ios::nocreate);
if (!indata)
{
cerr<<"Error opening file:" <<endl;
return 0;
}
//----------------------------------------------------------
//populates dictionary of known letters in text
vector<int> code(a, a + NUMELS);
vector<char> key(b, b + NUMELS);
//----------------------------------------------------------
//call to function to start compression of text file
compressText(code, key);
for(i=0;i<NUMELS;i++)
return 0;
}
//*************************************************************
$ g++ zipc.cpp
$ a.out
B<--c value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
<---key value
AB<---buffer value
Segmentation Fault
$ ^D
script done on Sun Apr 17 17:29:56 2005